如何在超类中处理UIViewController子类中的方法

时间:2011-03-08 14:27:59

标签: iphone

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

我正在向名为myapp的{​​{1}}添加一个UIViewController子类。

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

mysubclass

我这样称呼这个方法:

以同样的方式我需要在pos.y = 320处反转位置。我的代码看起来像这样。

-(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;

}

但它不起作用,可能是我们无法在subviewcontroller类中处理这个问题的原因,如果它是如何从超类处理它。

如果我的猜测错了,任何人都可以建议错误。

提前感谢你。

1 个答案:

答案 0 :(得分:0)

您是否实施了shouldAutorotateToInterfaceOrientation?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}


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