我正在创建一个名为myapp的基于am视图的应用程序。
我正在向myapp添加一个名为mysubclass的UIViewController子类。
在mysubclass中,我正在制作一些图像的动画。我在mysubclass中的代码如下所示:
-(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;
}我像这样调用这个方法:
以同样的方式,我需要反转pos.y =320的位置。我的代码如下所示。
-(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];
}
}但它不能工作,可能是因为我们不能在subviewcontroller类中处理它,如果是我如何在超类中处理它。
如果我的猜测是错的,有没有人能建议一下错在哪里?
提前谢谢你。
发布于 2011-03-09 00:03:36
你实现shouldAutorotateToInterfaceOrientation了吗?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}顺便说一下,您可以将代码简化为一个使用self.view.bounds.size.height或类似方法的"onTimer“方法,而不是硬编码值420和320。
https://stackoverflow.com/questions/5233806
复制相似问题