2010-05-04 61 views
0

我想表示在iphone屏幕上旋转的视图。我有一个按钮,当你按下它时,视图旋转180度。iphone:重复转换

我的问题是,这只是第一次。

下面是代码:

-(IBAction) flip:(id)sender{ 

    CGAffineTransform transform; //the transform matrix to be used below 

    //BEGIN ANIMATIONS 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:2.0]; 

    //animate 
    if (flag){ 
     transform = CGAffineTransformMakeRotation(RADIANS(180)); 
    } else { 
     transform = CGAffineTransformMakeRotation(RADIANS(-180)); 
    } 
    flag = !flag; 
    transform = CGAffineTransformTranslate(transform, 0, 0); 
    self.mySuview.transform = transform; 

    //COMMIT ANIMATIONS 
    [UIView commitAnimations]; 

} 

第一次单击,视图旋转好了,但是当你再次单击什么也不会发生。没有错误,没有改变的观点。

我错过了什么?

感谢 Gonso

+0

尝试调试此方法以检查是否按预期方式处理它 – Vladimir 2010-05-04 10:48:21

+0

是方法每次都运行,但没有任何反应 – gonso 2010-05-06 10:11:09

回答

0

你基本上设置变换是相同的两个时代。在你的else {}语句中,使用:

transform = CGAffineTransformMakeRotation(RADIANS(0));

正如您所看到的,您的代码没有使用180并且加上-180,而是使用180并将其设置为-180。