2014-02-17 19 views
0

我使用這個代碼改變2 UIView之間:的UIView transitionFromView更改視圖HEIGH

UIViewAnimationOptions animationType = UIViewAnimationOptionTransitionFlipFromLeft; 

[UIView transitionFromView:self.playlistTableView toView:self.playerView duration:0.5 options:animationType completion:^(BOOL finished){ 
    [self.containerView sendSubviewToBack:self.upperView]; 
    [self.containerView sendSubviewToBack:self.playerView]; 

    self.isPlaylistVisible = !self.isPlaylistVisible; 
    isControlsHidden = NO; 
}]; 

,我注意到一個奇怪的現象,當我做出的翻轉self.playerView的高度丟失20像素和後一秒它增加回正常的幀大小。

我嘗試將animationType更改爲UIViewAnimationOptionLayoutSubviews,現在當我在視圖之間切換時,不會發生此行爲。 任何想法可能是什麼問題?

+0

檢查自動尺寸。首先查看的autoresizingMask。和self.containerView的autoresizesSubviews屬性。 – Avt

+0

我應該設置爲autoresizesSubviews? – MTA

+0

autoresizesSubviews = NO。 autoresizingMask = UIViewAutoresizingNone。 – Avt

回答

6

請嘗試此代碼。

 [self.upperView setHidden:YES]; 
     [self.playerView setHidden:NO]; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES]; 
     [UIView setAnimationDuration:1.0]; 
     [UIView commitAnimations]; 
     [containerView addSubview:self.playerView]; 

爲了得到相反的情況

[self.upperView setHidden:NO]; 
    [self.playerView setHidden:YES]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView commitAnimations]; 
    [containerView addSubview:self.upperView];