簡體   English   中英

iPhone:重復轉換

[英]iphone: repeating a transformation

我試圖代表一個在iPhone屏幕上旋轉的視圖。 我有一個按鈕,當您按下它時,視圖旋轉180度。

我的問題是,這只能在第一次使用。

這是代碼:

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

}

當您第一次單擊,視圖旋轉好了,但是當你再次單擊什么也不會發生。 沒有錯誤,視圖上沒有更改。

我想念什么?

謝謝貢索

您基本上將轉換設置為兩次都相同。 在您的else {}語句中,使用:

變換= CGAffineTransformMakeRotation(RADIANS(0));

照原樣,您的代碼不是采用180並加上-180,而是采用180並將其設置為-180。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM