我正在創建一個名爲myapp
的基於UIView的應用程序。如何處理超類UIViewController子類中的方法
我正在添加一個名爲mysubclass
的myapp
的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類來處理這個問題,如果是我該如何處理這從超類。
如果我的猜測是錯誤的,任何人都可以請建議什麼是錯的。
謝謝你提前。
你提的問題是非常不清楚。你是什麼意思「這不起作用?」 – 2011-03-08 14:55:53
真的沒有得到你想說的! – SPatil 2011-03-08 15:45:57