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

Iphone 如何从超类处理UIViewController子类中的方法,iphone,Iphone,我正在创建一个名为myapp的基于UIView的应用程序 我正在向myapp添加一个名为mysubclass的UIViewController子类 在我的子类中,我正在制作一些图像的动画。我在mysubclass中的代码如下所示: -(void) onTimer { balloon.center = CGPointMake(balloon.center.x,balloon.center.y+pos.y); balloon1.center = CGPointMake(ballo

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

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

在我的子类中,我正在制作一些图像的动画。我在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类中处理这个问题,如果是的话,我如何从超类处理这个问题

如果我猜错了,谁能告诉我是怎么回事吗


先谢谢你

您是否实现了shouldAutorotateToInterfaceOrientation

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

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

您的问题非常不清楚。你说这不起作用是什么意思?真的没有得到你想说的!旋转设备时,是否会调用AnimateSecond Half RotationFromInterfaceOrientation?否,它将在myappViewController.m中调用。m不在mysubclass.mIs mysubclass中UIViewController或UIView?我的子类是如何创建的?我不明白。显示mysubclass的.h,并显示如何创建和显示它。