热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在UIViewController中停止所选子视图的自动操作-HowtostopautorotionofselectedsubviewinUIViewController

IhaveaViewControllerIhavestartedanAVCaptureSessionontheviewoftheViewController,我有一个

I have a View Controller I have started an AVCaptureSession on the view of the View Controller,

我有一个View Controller我已经在View Controller的视图上启动了一个AVCaptureSession,

  AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

Now I add it like this,

现在我像这样添加它,

[self.view.layer addSubLayer: captureVideoPreviewLayer]

I also have added two buttons on storyboard in this View Controller, On rotation of the device the self.view should not rotate as it has the camera going on but I want the two buttons which are capture and cancel button to align and rotate, How can I achieve this using storyboard.

我还在这个视图控制器的故事板上添加了两个按钮,在设备旋转时,self.view不应该旋转,因为它有摄像头继续但是我想要两个按钮,它们是捕获和取消按钮来对齐和旋转,如何我可以使用故事板来实现这一点吗?

1 个解决方案

#1


0  

Unfortunately this is not as easy as it should be. You may not simply "not rotate" a single view while the rest of the UI is rotated.

不幸的是,这并不像应该的那样容易。在旋转UI的其余部分时,您可能不会简单地“旋转”单个视图。

Since you are using a camera I suggest you to capture the the device orientation change through the notification center while keeping the controller orientation locked to whatever is your default or current state.

由于您使用的是相机,我建议您通过通知中心捕获设备方向更改,同时保持控制器方向锁定为您的默认或当前状态。

On orientation change you should then try and rotate the view with your buttons or anything else that should rotate. This is best done if all of the controls are added to a single view which has the same size as the view controller and is centered in the view controller. This means the constraints for this view are center x, center y, width, height. You need outlets for width and height and set them manually in the code. When view will layout subviews (it is a method to override in the view controller) simply set the width and height to the same as is the view controller controller.view.frame.size. Till this point your application should look exactly the same as it does now if rotations are disabled.

在方向更改时,您应该尝试使用按钮或其他任何应旋转的视图旋转视图。如果将所有控件添加到与视图控制器大小相同且在视图控制器中居中的单个视图,则最好这样做。这意味着此视图的约束是中心x,中心y,宽度,高度。您需要宽度和高度的出口,并在代码中手动设置。当视图将布局子视图(它是在视图控制器中覆盖的方法)时,只需将宽度和高度设置为与视图控制器controller.view.frame.size相同。到目前为止,如果禁用旋转,您的应用程序应该与现在完全相同。

Now for the fun part: You need to check the current orientation and apply a rotation transform on the view with the buttons. What you need is a property holding the current interface orientation and upon changing that orientation you should apply a different transform to the view. The device orientation will not give you the interface orientation as device orientation includes extra positions. So when device orientation changes you need to use a switch statements and only on the 4 orientations that make sense should you change the interface orientation.

现在有趣的部分:您需要检查当前方向并使用按钮对视图应用旋转变换。您需要的是保持当前界面方向的属性,并且在更改该方向时,您应该对视图应用不同的变换。设备方向不会为您提供界面方向,因为设备方向包含额外的位置。因此,当设备方向发生变化时,您需要使用开关语句,并且只有在有意义的4个方向上才能更改界面方向。

Once you have all that you should create a method that takes a user interface orientation as input and and will reposition the view with the buttons. (assuming you use portrait by default) You need to swap the width and height when the interface orientation is landscape as in widthConstraint.cOnstant= controller.view.frame.size.height and apply a rotation transform depending on the orientation.

完成所有操作后,您应该创建一个将用户界面方向作为输入的方法,并使用按钮重新定位视图。 (假设您默认使用纵向)当界面方向为横向时,您需要交换宽度和高度,如widthConstraint.cOnstant= controller.view.frame.size.height,并根据方向应用旋转变换。

This method should be called when:

应在以下情况下调用此方法:

  • The controller will become visible with the application status bar orientation
  • 应用程序状态栏方向将显示控制器

  • When view will layout with the same orientation as was previously saved from view will become visible or device orientation change
  • 如果视图的布局方向与之前从视图中保存的方向相同,则会显示可见或设备方向更改

  • When device orientation changes if the new orientation makes sense and is different then the currently set interface orientation
  • 如果新方向有意义并且与当前设置的界面方向不同,则设备方向会发生变化

There are other ways of doing this though. For instance you may keep the rotation of the view controller and rotate the camera view with the same procedure and this is even easier since you may use viewWillTransitionToSize and animateAlongsideTransition but the animation will probably not be acceptable as you may see black parts when the view controller is oriented. Though I am not sure that will actually occur and even if it does it might be possible to fix it with disabling bound clipping on the controller view.

还有其他方法可以做到这一点。例如,您可以保持视图控制器的旋转并使用相同的步骤旋转摄像机视图,这更容易,因为您可以使用viewWillTransitionToSize和animateAlongsideTransition,但动画可能不会被接受,因为您可能会看到视图控制器时的黑色部分是面向的。虽然我不确定实际会发生什么,即使它确实发生了,也可以通过在控制器视图上禁用绑定剪辑来修复它。


推荐阅读
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 安卓select模态框样式改变_微软Office风格的多端(Web、安卓、iOS)组件库——Fabric UI...
    介绍FabricUI是微软开源的一套Office风格的多端组件库,共有三套针对性的组件,分别适用于web、android以及iOS,Fab ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 有没有一种方法可以在不继承UIAlertController的子类或不涉及UIAlertActions的情况下 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • 本文介绍了MVP架构模式及其在国庆技术博客中的应用。MVP架构模式是一种演变自MVC架构的新模式,其中View和Model之间的通信通过Presenter进行。相比MVC架构,MVP架构将交互逻辑放在Presenter内部,而View直接从Model中读取数据而不是通过Controller。本文还探讨了MVP架构在国庆技术博客中的具体应用。 ... [详细]
  • jQuery实现简单的动画效果及用法详解
    本文详细介绍了使用jQuery实现简单动画效果的方法,包括显示/隐藏、向上收缩/向下展开、淡入/淡出、自定义动画等。同时提供了具体的用法示例,并解释了参数的含义和使用技巧。通过本文的学习,读者可以掌握如何使用jQuery实现各种动画效果,为网页增添生动和互动性。 ... [详细]
  • win10电脑蓝屏代码0x000000a5无法进入系统解决方法详解
    许多用户在使用电脑的时候遇到蓝屏问题,重启无法进入系统。本文提供了解决方法:调整BIOS设置、禁用安全启动、重装系统等。如果以上方法都无法解决问题,需要重新安装一个系统。详细步骤请参考正文内容。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
author-avatar
吃碰杠和_338
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有