Iphone 在接口旋转期间淡入/淡出
当我的iPhone界面旋转时,我想对UIViewController的特定UIView进行淡入/淡出。。。像Iphone 在接口旋转期间淡入/淡出,iphone,animation,rotation,Iphone,Animation,Rotation,当我的iPhone界面旋转时,我想对UIViewController的特定UIView进行淡入/淡出。。。像 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [UIView beginAnimations:nil context:nil]; [UIView setAnimationD
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 0;
[UIView commitAnimations];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 1;
[UIView commitAnimations];
}
但是动画在旋转开始之前没有完成(我们可以看到视图开始自动调整大小)
有没有办法延迟旋转开始
“duration”是旋转动画的持续时间,对吗?您的问题源于这样一个事实:在调用willRotateToInterfaceOrientation:时,正在旋转的视图已经设置了其方向属性,处理旋转的动画块也准备在单独的线程上运行。发件人: 从用于旋转视图的动画块内调用此方法。您可以替代此方法,并使用它来配置视图旋转期间应出现的其他动画
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[UIView animateWithDuration:0.25 animations:^{
theview.alpha = 0.0;
}];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
我建议覆盖shouldAutorotateToInterfaceOrientation:方法来触发动画,然后对支持的方向返回YES:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == (UIDeviceOrientationPortrait || UIDeviceOrientationPortraitUpsideDown) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 0;
[UIView commitAnimations];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 1;
[UIView commitAnimations];
}
return YES;
}
这应该确保在设置UIViewController的方向和启动旋转动画之前,动画会运行。根据设备硬件速度的不同,您可能需要添加一个轻微的延迟来获得想要的效果。我发现,在与前面动画相同的时间内运行当前运行循环,实际上确实延迟了旋转
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[UIView animateWithDuration:0.25 animations:^{
theview.alpha = 0.0;
}];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
嗨,你是怎么解决问题的?我没解决。我只是将动画持续时间设置为0.1s