how to move simple view in self boundary of simulator of iphone infinitely without animation in objective c?

StackOverflow https://stackoverflow.com/questions/22523943

Question

I want to move my UIView of size (x=50,y=50) in the boundary of simulator screen means rectangular without animation infinitely.

Was it helpful?

Solution

To moving view continuously in your simulator boundary you have to put logic there is no predefined method without animation. if you are using animation then below given link is useful. How to repeat animation from current state not from startingstate? or without animation the below code will help you. And yes please note that **

  • pos

** is a object of CGPoint class and you don't have to allocate it simply declare in interface.

- (void)viewDidLoad

{

 pos  = v1.center;
NSLog(@"POSITION === %f",pos.x);

 [NSTimer scheduledTimerWithTimeInterval:0.05
                                 target:self
                               selector:@selector(rotateBoundary)
                               userInfo:nil
                                repeats:YES];

[super viewDidLoad];


 //[self performSelector:@selector(rotateBoundary) withObject:self afterDelay:5.0];
// Do any additional setup after loading the view, typically from a nib.

}

-(void)rotateBoundary {

if (pos.x>=20 && pos.x<=290 && pos.y==25) 
{      
    NSLog(@"Top left to right.");
    pos.x+=5;
    v1.center = pos;
    NSLog(@"pos.x   ===  %f",pos.x);
}
if(pos.x >= 290 && pos.y<=430)
{
    NSLog(@"Right top to down.");
    pos.y+=5;
    v1.center = pos;
    NSLog(@"pos.y   ===  %f",pos.y);
}

if(pos.y == 430 && pos.x>=20) 
{
    NSLog(@"Down right to left.");
    pos.x-=5;
    v1.center = pos;
    NSLog(@"pos.x   ===  %f",pos.x);
}
if (pos.x <= 20 && pos.y>=25) 
{
    NSLog(@"Down left to top.");
    pos.y-=5;
    v1.center = pos;
    NSLog(@"pos.y   ===  %f",pos.y);
} 

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top