2012-11-23 75 views
2

我使用NSTimer移動UIImageView,因爲幾個原因動畫UIView動畫。當它移動時,我也要旋轉它。可能嗎?一些示例代碼? 感謝iOS - 移動時旋轉圖像

+0

你應該提供一些更多的上下文,以及你嘗試過的。 – rdurand

+0

然後在這裏查看旋轉UIImageView:http://www.xappsoftware.com/wordpress/2012/05/24/how-to-rotate-a-uiimageview-roulette-tutorial/ – rdurand

+0

@rdurand您已鏈接的代碼是好的,但是當我使用它時,似乎我的形象正在延伸。 –

回答

0

我找到了解決辦法。當我移動我的UIImageView時,我改變了它的框架,改變了它的值y。所以,當一個物體的框架發生變化時,不可能轉換它。所以,爲了移動我的UIImageView,我現在改變它的center屬性,這個轉換就像一個魅力!

0

應用轉換到視圖

- (void)viewDidAppear:(BOOL)animated { 
    self.imageView.contentMode = UIViewContentModeScaleAspectFit; //if not set in xib it must be set here 
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(move:) userInfo:nil repeats:YES]; 
} 

- (void)move:(id)timer { 
    CGRect f = self.imageView.frame; 
    static CGFloat angle = 1; 

    f.origin.x += 5; 
    f.origin.y += 10; 
    self.imageView.frame = f; 

    self.imageView.transform = CGAffineTransformMakeRotation(angle); //!!! 
    angle += 10; 
} 
+0

當我使用這段代碼時,似乎我的圖像正在擴展,我不知道爲什麼。 –

+0

用示例代碼編輯了我的答案 –