Objective c UIView动画不适用于横向模式
我使用的是一个UIView动画,其中第二个视图从底部显示并到达视图的中心。虽然我的应用程序支持横向模式,并且我实现了“WillAnimateRotationInterfaceOrientation:toInterfaceOrientation”方法,但它在横向模式下无法工作。这是我的密码:Objective c UIView动画不适用于横向模式,objective-c,uiviewanimation,Objective C,Uiviewanimation,我使用的是一个UIView动画,其中第二个视图从底部显示并到达视图的中心。虽然我的应用程序支持横向模式,并且我实现了“WillAnimateRotationInterfaceOrientation:toInterfaceOrientation”方法,但它在横向模式下无法工作。这是我的密码: -(void) viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.view.backgroundCol
-(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);
}
我猜我将第二个视图的框架设置在错误的位置…您使用了
WillAnimateRotationInterfaceOrientation
,但您必须使用didRotateFromInterfaceOrientation
WillAnimateRotationInterfaceOrientation
将在旋转前为您提供方向
所以用这个
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
imageView.center = self.view.center;
}
这肯定会帮助你
祝您愉快………..-:)