【问题标题】:Changing UIImagView image when iPad change its orientation当 iPad 更改其方向时更改 UIImagView 图像
【发布时间】:2011-11-12 20:40:56
【问题描述】:

当 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];
} 
}

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

提交

【问题讨论】:

    标签: ipad uiimageview uiimage interface-orientation uideviceorientation


    【解决方案1】:

    例如,您可以使用具有两种内容的两个视图并实现 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: 显示另一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多