0

我正在使用以下代码在 iPad 方向更改时更改 UIImageView 的图像

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight))
{
    self.background=self.background_D;
    self.backgroundImage.backgroundColor = [UIColor colorWithPatternImage:self.background];
} 
else  if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown))
{
    self.background=self.background_P;
    self.backgroundImage.backgroundColor = [UIColor colorWithPatternImage:self.background];
} 
}

一切正常,除了当我改变方向时它需要暂停一秒钟然后改变图像。同时它以平铺格式显示相同的旧图像。我应该怎么做才能避免这种情况?

苏米特

4

1 回答 1

0

例如,您可以使用两个包含内容的视图并实现willRotateToInterfaceOrientation:并在其中放置一个动画,其中一个视图淡出,另一个视图淡入。如果您设置正确的时间,您的过渡应该是平滑的,并且在方向交换时完成完毕。要为您制作动画,请使用其中一种beginAnimations:方法和相关方法,或者在 iOS 4 以上[UIView animateWithDuration:delay:options:animations:completion:]http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial是动画的入门者。

更好的方法是实现willAnimateRotationToInterfaceOrientation:duration:已经在动画块中调用的方法。在这里,您只需重新配置块的 alpha 值,其余的将由动画完成。请注意,或者您甚至可以实现willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:可以隐藏可见图像willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:的位置以及显示另一个图像的位置。

于 2011-11-12T21:20:36.960 回答