• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:11:47 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

- (BOOL)shouldAutorotate {
  return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  return UIInterfaceOrientationPortrait;
}

- (void)orientationDidChangeNSNotification*)note {
  UIDeviceOrientation orientation = [UIDevice currentDevice].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;
  [self rotateInterfaceToOrientation:self.currentOrientation];
}

- (void)rotateInterfaceToOrientationUIInterfaceOrientation)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
}

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

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

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

当我使用键盘或 UIAlertView 显示提示时,它们的方向是错误的。再次模拟器:http://gfycat.com/SelfreliantPointedEwe .

有没有办法从 View Controller 中指定 View 当前是纵向还是横向?或者有没有办法在不使用自动布局调整大小/布局的情况下手动旋转屏幕?



Best Answer-推荐答案


通过旋转和 reshape View 来应用旋转。如果您对 View 应用反向旋转和整形,它将看起来不旋转。

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

旋转到横向时,应用将 View 旋转 (-) 90 度的变换,并手动交换边界的宽度和高度。您的 View 将不再出现旋转,但界面方向不会受到影响。还可以将任何 subview 旋转相反的角度并移动它们以匹配重新调整的边界。

关于ios - 相机应用程序,如屏幕旋转和导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32253718/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap