2012-12-04 53 views
1

我正在使用UIView動畫,其中第二個視圖從底部出現並出現在視圖的中心。但它不能在橫向模式下工作,儘管我的應用程序支持橫向模式,而且我實現了「willAnimateRotationToInterfaceOrientation:toInterfaceOrientation」方法。這裏是我的代碼:UIView動畫不適用於橫向模式

-(void) viewWillAppear:(BOOL)animated{ 

    [super viewWillAppear:animated]; 
    self.view.backgroundColor = [UIColor blackColor]; 

    imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0, 499, 320, 0)]; 
    imageView.image = [UIImage imageNamed:@"trans.png"]; 
    [imageView setClipsToBounds:YES]; 
    [imageView setContentMode:UIViewContentModeBottom]; 



    [self.view addSubview:imageView]; 


    [UIView animateWithDuration:1.0f 
          delay:0.5f 
         options:UIViewAnimationOptionCurveEaseOut 
        animations:^(void) { 
         imageView.frame = CGRectMake(0, 92, 320, 320); 

        } 
        completion:NULL]; 


} 


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    CGRect screen = [[UIScreen mainScreen] bounds]; 
    float pos_y, pos_x; 
    pos_y = UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]) ? screen.size.width/2 : screen.size.height/2; 
    pos_x = UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]) ? screen.size.height/2 : screen.size.width/2; 

    imageView.center = CGPointMake(pos_x, pos_y); 

} 

我猜I'm設置錯了地方第二種觀點的框架...

回答

0

您已經使用willAnimateRotationToInterfaceOrientation,但你必須使用didRotateFromInterfaceOrientation

willAnimateRotationToInterfaceOrientation將在旋轉之前給你方向。

所以用這個..........

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    imageView.center = self.view.center; 
} 

這一定會幫助你...

有一個幸福的編碼.......... ................. - :)

相關問題