我们应该使用2个不同的图像或单个图像进行横向和纵向模式

时间:2011-12-04 10:29:10

标签: iphone ipad xcode4 ios4

我正在为iPad做一个应用程序,我们在其中添加了两个用于Landscape的图像,另一个用于纵向模式,我已经编写了代码。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
// in this method we have called landscape and portrait frames basing on the
// status bar rotation if it is turned to landscape then the landscape image
// is called and the textfields frames are set else portrait image is set and
// then the textfield frames are set on to it.  
}  

有人可以通过说是使用2个不同图像的正确方法来帮助我,或者我们应该只使用1个图像用于横向和纵向。如果是这样,我们怎样才能使用那些只有单个图像?我的应用程序因此而崩溃。请帮助我。

提前致谢。

3 个答案:

答案 0 :(得分:1)

使用两个不同的图像没有什么害处它只是增加了图像包的大小..我已经为appstore上的应用程序做了这个..一个MNC的银行ipad应用程序。所以没有伤害继续使用它。我个人认为这比处理图像并调整大小更好。

答案 1 :(得分:1)

您可能最好有两张图片,您可以执行以下操作:

编辑:我添加了一些代码,以确保您的图片填满整个可用空间。

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){

[landscapeimage setHidden:NO];
[portraitimage setHidden:YES];

CGRect landscapeframe = landscapeimage.frame;
landscapeframe.origin.x = 0; // new x coordinate
landscapeframe.origin.y = 0; // new y coordinate
landscapeframe.size.width = 1024;
lanscapeframe.size.height = 768;

}

else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){

[landscapeimage setHidden:YES];
[portraitimage setHidden:NO];

CGRect portraitframe = portraitimage.frame;
portraitframe.origin.x = 0; // new x coordinate
portraitframe.origin.y = 0; // new y coordinate
portraitframe.size.width = 768;
portraitframe.size.height = 1024;

}

希望这能帮到你!

答案 2 :(得分:1)

Hello kinthali根据文档

处理视图轮播

  

默认情况下,UIViewController类以纵向模式显示视图   只要。要支持其他方向,您必须覆盖    shouldAutorotateToInterfaceOrientation :方法并返回YES为any   您的子类支持的方向。如果自动调整属性   您的视图配置正确,这可能是您所需要做的。   但是,UIViewController类为您提供了额外的挂钩   根据需要实施其他行为。

     

暂时关闭不需要或可能的功能   否则在方向改变期间会导致问题,你可以   覆盖 willRotateToInterfaceOrientation :duration:方法和   在那里执行所需的操作。然后你可以覆盖    didRotateFromInterfaceOrientation :方法并使用它来重新启用它们   一旦方向改变完成,就会有功能。

根据您的问题,您需要做的是在shouldAutorotateToInterfaceOrientation中为支持的方向返回Yes,您可以调用一个函数来设置背景图像(两个不同的肖像和横向图像),如下所示

[self updateBackgroundImageForOrientation:PROBABLE_INTERFACE_ORIENTATION];

在方法实现中,您可以更新背景图像。这样您就可以实现所需的行为。由于您实际上没有发布任何功能代码,因此很难指出崩溃的原因。您可以调试并查看控制台日志,了解崩溃的根本原因。