I am creating a UIView-based application named myapp
.
I am adding a UIViewController subclass to myapp
named mysubclass
.
In mysubclass
I am animating some images. My code in mysubclass looks like this:
-(void) onTimer {
balloon.center = CGPointMake(balloon.center.x,balloon.center.y+pos.y);
balloon1.center = CGPointMake(balloon1.center.x,balloon1.center.y+pos1.y);
balloon2.center = CGPointMake(balloon2.center.x,balloon2.center.y+pos2.y);
balloon3.center = CGPointMake(balloon3.center.x,balloon3.center.y+pos3.y);
balloon4.center = CGPointMake(balloon4.center.x,balloon4.center.y+pos4.y);
balloon5.center = CGPointMake(balloon5.center.x,balloon5.center.y+pos5.y);
if(balloon.center.y > 420 || balloon.center.y < 25)
pos.y = -pos.y;
if(balloon1.center.y > 420 || balloon1.center.y < 25)
pos1.y = -pos1.y;
if(balloon2.center.y > 420 || balloon2.center.y < 25)
pos2.y = -pos2.y;
if(balloon3.center.y > 420 || balloon3.center.y < 25)
pos3.y = -pos3.y;
if(balloon4.center.y > 420 || balloon4.center.y < 25)
pos4.y = -pos4.y;
if(balloon5.center.y > 420 || balloon5.center.y < 25)
pos5.y = -pos5.y;
}
I am calling this method like this:
in the same way i need to reverse the position at pos.y = 320.my code is look like this.
-(void) onTimer1 {
balloon.center = CGPointMake(balloon.center.x,balloon.center.y+pos.y);
balloon1.center = CGPointMake(balloon1.center.x,balloon1.center.y+pos1.y);
balloon2.center = CGPointMake(balloon2.center.x,balloon2.center.y+pos2.y);
balloon3.center = CGPointMake(balloon3.center.x,balloon3.center.y+pos3.y);
balloon4.center = CGPointMake(balloon4.center.x,balloon4.center.y+pos4.y);
balloon5.center = CGPointMake(balloon5.center.x,balloon5.center.y+pos5.y);
if(balloon.center.y > 320 || balloon.center.y < 25)
pos.y = -pos.y;
if(balloon1.center.y > 320 || balloon1.center.y < 25)
pos1.y = -pos1.y;
if(balloon2.center.y > 320 || balloon2.center.y < 25)
pos2.y = -pos2.y;
if(balloon3.center.y > 420 || balloon3.center.y < 25)
pos3.y = -pos3.y;
if(balloon4.center.y > 320 || balloon4.center.y < 25)
pos4.y = -pos4.y;
if(balloon5.center.y > 320 || balloon5.center.y < 25)
pos5.y = -pos5.y;
}
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
UIInterfaceOrientation toorientation = self.interfaceOrientation;
if ((toorientation == UIInterfaceOrientationPortrait) || (toorientation == UIInterfaceOrientationPortraitUpsideDown) ) {
timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
else{
timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer1) userInfo:nil repeats:YES];
}
}
but it not work开发者_开发技巧ing,may be the reason is we can't able to handle this in subviewcontroller class,if it is how can i handle this from super class.
if my guess is wrong,can any one please suggest what's the wrong.
Thank u in advance.
Have you implemented shouldAutorotateToInterfaceOrientation?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
By the way you can simplify the code a bit to just one "onTimer" method that uses self.view.bounds.size.height
or similar instead of the hard-coded values 420 and 320.
精彩评论