1

我正在使用 UIView 动画,其中第二个视图从底部出现并到达视图的中心。但它不能在横向模式下工作,尽管我的应用程序支持横向模式并且我实现了方法“willAnimateRotationToInterfaceOrientation:toInterfaceOrientation”。这是我的代码:

-(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);

}

我想我将第二个视图的框架设置在错误的位置...

4

1 回答 1

0

你用过willAnimateRotationToInterfaceOrientation,但你必须用didRotateFromInterfaceOrientation

willAnimateRotationToInterfaceOrientation旋转前会给你方向。

所以用这个…………

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

这绝对会帮助你...

祝你编码愉快............ - :)

于 2013-03-15T10:10:37.430 回答