Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在设备旋转时更改视图控制器_Ios_Objective C_Iphone_Xcode - Fatal编程技术网

Ios 在设备旋转时更改视图控制器

Ios 在设备旋转时更改视图控制器,ios,objective-c,iphone,xcode,Ios,Objective C,Iphone,Xcode,我正在做我的第一个Xcode项目,我想知道是否有可能有两个视图控制器,一个是纵向视图,另一个是水平视图。是否有任何方法可以将这两个视图控制器链接起来,以便在设备旋转时视图将发生更改?在viewDidLoad中,将旋转后的视图添加到superview,并向UIDeviceOrientationDidChangeNotification注册一个观察者,对象为:[UIDevice currentDevice]。 - (void)deviceOrientationChangedNotification:

我正在做我的第一个Xcode项目,我想知道是否有可能有两个视图控制器,一个是纵向视图,另一个是水平视图。是否有任何方法可以将这两个视图控制器链接起来,以便在设备旋转时视图将发生更改?

在viewDidLoad中,将旋转后的视图添加到superview,并向UIDeviceOrientationDidChangeNotification注册一个观察者,对象为:[UIDevice currentDevice]。
- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}
在选择器上设置其帧。然后旋转新的旋转视图,并将旧视图的alpha设置为0.0

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}

我不建议你这么做,因为苹果公司设计了一些直观的UI控制器来管理应用程序的导航,你不能让用户猜测如何在你的应用程序中执行某些任务,你必须准确地向他们展示如何执行。
因此,旋转设备转到另一个视图控制器,正如您所说:旋转设备时,我想要一个完全不同的视图。。。这不是个好主意

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}
阅读完整的iOS人机界面指南,了解哪些是推荐的,哪些不是:

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}
请特别阅读:

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}
避免在布局上进行无谓的更改。在所有环境中都有类似的体验,让人们在旋转设备或在不同的设备上运行应用程序时保持自己的使用模式。例如,如果使用栅格在水平规则环境中显示图像,则不必在水平紧凑环境中的列表中显示相同的信息,尽管可以调整栅格的尺寸

- (void)deviceOrientationChangedNotification:(NSNotification *)notification 
{
     UIDevice *device = [notification object];
     UIDeviceOrientation orientation = device.orientation;

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
     {
        [rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
        rotatedView.frame = [UIScreen mainScreen].bounds;
        oldView.alpha = 0.0;
     }
}

您希望在旋转时拥有完全不同的视图,还是希望子视图调整其大小?如果是后者,你应该使用AutoLayout或Size类。当它旋转时,我想要一个完全不同的视图。也许你可以详细说明你反对它的原因?HIG涵盖了很多领域——仅仅提供这种联系并不能真正帮助解释你的推理。(另外,让你的答案完全依赖于一个链接从来都不是一个好主意——链接确实会断开。)如果要切换到另一个viewController,我必须旋转divice,这不是一个好主意,这不是一个直观和正确的方法来管理应用程序的导航(这正是他想要的)。很明显,他是一个非常业余的人,没有读过苹果关于iOS接口的指南(我推荐他使用链接,我不会用这种方式向他解释所有的指南lol)。一个应用程序在不同的方向上呈现出不同的形式并不罕见——例如,尝试旋转苹果的“股票”应用程序。有时,单个视图控制器可以管理两个方向,但同时为每个方向使用单独的控制器可能是有意义的。请注意,无偿这个词并不意味着全部。我不是说你错了,只是说除非你解释一下,否则不可能理解你的建议。是的,我知道。我们可以在不同的方向管理应用程序的外观。但是,例如,执行segue或显示其他视图控制器并不是管理应用程序UI元素的外观或分布的实用方法。不过,你也没有错,我的答案可能会更好。非常感谢。在示例代码中,您在哪里“将旋转视图添加到superview”呢?我已更正,我将视图添加为viewDidLoad中的子视图。