2016-07-29 51 views
2

我有一個簡單的UIView:使用cgaffinetransformmakescale和cgaffinetransformmakerotation變形我看來

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; 
view.backgroundColor = [UIColor greenColor]; 
[self.view addSubview:view]; 
self.someView = view; 

然後我做這個

[UIView animateWithDuration:10 
         delay:1 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
    self.someView.center = CGPointMake(CGRectGetWidth(self.view.bounds) - CGRectGetWidth(self.someView.frame)/2, 150); 

        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI); 
        self.someView.transform = CGAffineTransformScale(transform, 2, 0.5); 

} 
       completion:^(BOOL finished) { 

       }]; 

當執行這個簡單的動畫,變形。據我所知它應該旋轉並改變它的大小。我不明白爲什麼會發生這種情況,我該如何解決它?

謝謝

回答

1

問題是動畫組合縮放和旋轉。最終結果與單獨製作動畫相同,但不容易定義它們之間的幀。所以動畫框架會進行猜測,而這不是你所期待的。

如果您希望動畫分別顯示旋轉和縮放,則需要將它們分別應用於視圖層次結構。例如:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; 
view.backgroundColor = [UIColor greenColor]; 
[self.view addSubview:view]; 
self.someView = view; 

UIView *innerView = [[UIView alloc] initWithFrame:view.bounds]; 
innerView.backgroundColor = [UIColor blueColor]; 
[view addSubview:innerView]; 
self.someInnerView = innerView; 

動畫拆分變換:

[UIView animateWithDuration:10 
         delay:1 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
        self.someView.center = CGPointMake(CGRectGetWidth(self.view.bounds) - CGRectGetWidth(self.someView.frame)/2, 150); 

        self.someView.transform = CGAffineTransformMakeRotation(M_PI); 
        self.someInnerView.transform = CGAffineTransformMakeScale(2, 0.5); 

       } 
       completion:^(BOOL finished) { 

       }]; 
相關問題