iphone - 如何在自定义 iPhone 应用程序中从垂直 View 旋转到水平 View

标签 iphone orientation

我有一个 View Controller ,其中包含一个图形 View 和分段控件。如何让 View 旋转到水平方向?另外,是否可以加载另一个水平方向的 View ?

提前谢谢, 姆拉登

最佳答案

您可以通过以下方式实现定向支持:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
// Just delete the lines for the orientations you don't want to support
  if((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
     (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) ||
     (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)) ||
     (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))  {   
   return YES; 
   }
return NO;
}

然后在旋转时加载新的ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
  if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
     (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
  {    
    // Load the view controller you want to display in portrait mode...
  }
}

如果您想要平滑过渡,您甚至可以设置动画来操纵新 View 的 alpha 属性,就像您在 iPod 应用程序过渡到 CoverFlow 模式时看到的那样。

免责声明 支持界面旋转的首选方法在3.0中发生了变化。上面的方法仍然有效,但是有一种方法可以获得更流畅的动画。但我们不应该在这里谈论这一点。更多的。星期。

另一免责声明 支持界面旋转的首选方法在 6.0 中再次发生变化。上面的方法仍然有效,但是有一种方法可以获得更流畅的动画。

关于iphone - 如何在自定义 iPhone 应用程序中从垂直 View 旋转到水平 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/974905/

相关文章:

iphone - Objective-C - 在 NSAttributedString 中插入字符串?

xamarin.forms - 在 Xamarin Forms 中控制单页方向和 View 旋转

ios - 需要根据设备方向改变 NSLayoutConstraint 的乘数 : where to do it?

某些设备(不在 EXIF 中)拍摄时 Android 相机无法解释的旋转

ios - 将 iAd 横幅叠加到屏幕上而不是调整屏幕大小

iphone - Madgwick IMU算法在iphone上模拟

iphone - UIWebView - 自动调整大小,以便不需要滚动(在 webView 本身中)

iphone - 通过解析 XML 传递 UITableView

iPhone 开发 - 手动旋转 View

android - Android中的相机方向问题