首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理来自超类的UIViewController子类中的方法

如何处理来自超类的UIViewController子类中的方法
EN

Stack Overflow用户
提问于 2011-03-08 22:27:59
回答 1查看 214关注 0票数 0

我正在创建一个名为myapp的基于am视图的应用程序。

我正在向myapp添加一个名为mysubclass的UIViewController子类。

mysubclass中,我正在制作一些图像的动画。我在mysubclass中的代码如下所示:

代码语言:javascript
复制
-(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的位置。我的代码如下所示。

代码语言:javascript
复制
 -(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类中处理它,如果是我如何在超类中处理它。

如果我的猜测是错的,有没有人能建议一下错在哪里?

提前谢谢你。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-09 00:03:36

你实现shouldAutorotateToInterfaceOrientation了吗?

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

顺便说一下,您可以将代码简化为一个使用self.view.bounds.size.height或类似方法的"onTimer“方法,而不是硬编码值420和320。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5233806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档