[英]UIView Animation not working for Landscape mode
I am using an UIView Animation where a second view appears from bottom and comes up to the center of the view. 我正在使用UIView动画,其中第二个视图从底部出现,并到达该视图的中心。 But it is not working in landscape mode although my app supports landscape mode and I implemented the method "willAnimateRotationToInterfaceOrientation:toInterfaceOrientation".
但是,尽管我的应用程序支持横向模式,但是我实现了方法“ willAnimateRotationToInterfaceOrientation:toInterfaceOrientation”,但它无法在横向模式下工作。 Here is my code:
这是我的代码:
-(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 guess I´m setting the frame of the second view in the wrong place... 我想我在错误的位置设置了第二个视图的框架...
You have used willAnimateRotationToInterfaceOrientation
but you have to use didRotateFromInterfaceOrientation
. 您已经使用了
willAnimateRotationToInterfaceOrientation
但是必须使用didRotateFromInterfaceOrientation
。
willAnimateRotationToInterfaceOrientation
will give you orientation before rotating. willAnimateRotationToInterfaceOrientation
将为您提供旋转之前的方向。
So use this.......... 所以用这个..........
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
imageView.center = self.view.center;
}
This will definitely help you... 这肯定会帮助您...
Have a happy coding........................... -:) 祝您编码愉快...........................-:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.