菜鸟教程小白 发表于 2022-12-12 16:11:47

ios - 相机应用程序,如屏幕旋转和导航


                                            <p><p>我想复制原生相机应用程序的确切行为(包括其导航到图库和返回),当设备旋转时,UI 控件旋转到位而不是整个屏幕旋转。我能够通过在纵向模式下锁定屏幕并手动处理设备旋转通知来复制旋转行为,如下所示:</p>

<pre><code>- (BOOL)shouldAutorotate {
return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}

- (void)orientationDidChange:(NSNotification*)note {
UIDeviceOrientation orientation = .orientation;

UIInterfaceOrientation newOrientation = UIInterfaceOrientationPortrait;
switch (orientation) {
    case UIDeviceOrientationPortraitUpsideDown:
      newOrientation = UIInterfaceOrientationPortraitUpsideDown;
      break;

    case UIDeviceOrientationLandscapeLeft:
      newOrientation = UIInterfaceOrientationLandscapeLeft;
      break;

    case UIDeviceOrientationLandscapeRight:
      newOrientation = UIInterfaceOrientationLandscapeRight;
      break;

    case UIDeviceOrientationPortrait:
      newOrientation = UIInterfaceOrientationPortrait;
      break;

    default:
      newOrientation = self.currentOrientation;
      break;
}

if (newOrientation == self.currentOrientation) {
    return;
}
self.currentOrientation = newOrientation;
;
}

- (void)rotateInterfaceToOrientation:(UIInterfaceOrientation)orientation {
double rotationAngle = 0;
switch (orientation) {
    case UIInterfaceOrientationPortraitUpsideDown: rotationAngle = M_PI; break;
    case UIInterfaceOrientationLandscapeLeft: rotationAngle = M_PI_2; break;
    case UIInterfaceOrientationLandscapeRight: rotationAngle = -M_PI_2; break;
    default: rotationAngle = 0; break;
}

CGFloat angle = (float)rotationAngle;
self.defaultTransform = CGAffineTransformMakeRotation(angle);

... manual animation by setting transform
}
</code></pre>

<p>这很好用,并且完全符合我的需要。 </p>

<p>我的问题与应用程序的屏幕仍然是纵向的事实有关。</p>

<p>整个应用程序支持纵向和横向模式。当我导航到不同的屏幕并返回时,过渡会中断,因为它正在从横向 View 过渡到纵向 View 。就在过渡动画开始之前,以前的横向 View 将布局更改为纵向(尽管它被奇怪地拉伸(stretch)了)。来自模拟器的视频:<a href="http://gfycat.com/DeafeningGaseousBrant" rel="noreferrer noopener nofollow">http://gfycat.com/DeafeningGaseousBrant</a> .您可以在过渡开始时看到布局更改。它在设备上更加明显,因为您可以一直看到屏幕。值得一提的是,我正在使用自定义转换管理器使屏幕在导航时转向正确的方向(这可能解释了为什么 View 会像移动一样移动,但对有问题的行为没有影响)。</p>

<p>当我使用键盘或 UIAlertView 显示提示时,它们的方向是错误的。再次模拟器:<a href="http://gfycat.com/SelfreliantPointedEwe" rel="noreferrer noopener nofollow">http://gfycat.com/SelfreliantPointedEwe</a> .</p>

<p>有没有办法从 ViewController 中指定 View 当前是纵向还是横向?或者有没有办法在不使用自动布局调整大小/布局的情况下手动旋转屏幕?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>通过旋转和 reshapeView 来应用旋转。如果您对 View 应用反向旋转和整形,它将看起来不旋转。</p>

<p>通过 reshape ,我的意思是交换宽度和高度。</p>

<p>旋转到横向时,应用将 View 旋转 (-) 90 度的变换,并手动交换边界的宽度和高度。您的 View 将不再出现旋转,但界面方向不会受到影响。还可以将任何 subview 旋转相反的角度并移动它们以匹配重新调整的边界。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 相机应用程序,如屏幕旋转和导航,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32253718/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32253718/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 相机应用程序,如屏幕旋转和导航