2011-03-08 58 views
0

我正在創建一個名爲myapp的基於UIView的應用程序。如何處理超類UIViewController子類中的方法

我正在添加一個名爲mysubclassmyapp的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.my代碼的位置

是這個樣子。

-(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類來處理這個問題,如果是我該如何處理這從超類。

如果我的猜測是錯誤的,任何人都可以請建議什麼是錯的。

謝謝你提前。

+0

你提的問題是非常不清楚。你是什​​麼意思「這不起作用?」 – 2011-03-08 14:55:53

+0

真的沒有得到你想說的! – SPatil 2011-03-08 15:45:57

回答

0

你實施了shouldAutorotateToInterfaceOrientation嗎?

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


通過可以簡化代碼位辦法只有一個「的OnTimer」使用self.view.bounds.size.height或類似的,而不是硬編碼值420和320的方法

+0

是的,但沒有用。 – MaheshBabu 2011-03-10 14:26:08

+0

當你旋轉設備,willAnimateSecondHalfOfRotationFromInterfaceOrientation被調用? – Anna 2011-03-10 14:28:49

+0

不,它會在myappViewController.m中調用而不在mysubclass.m中 – MaheshBabu 2011-03-10 14:32:21

相關問題