2012-12-04 46 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; 
} 

这一定会帮助你...

有一个幸福的编码.......... ................. - :)

相关问题