[iOS] iOS 6的Rotation http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/

本文详细解析了iOS6中旋转功能的变化,并提供了关键代码示例。包括UIViewController方法的更新,如何在不同设备上设置orientation,以及在不同视图控制器中应用这些设置的方法。同时讨论了iOS4和iOS5与iOS6之间的兼容性问题,以及在使用导航控制器时遇到的限制和解决方案。
iOS 6的rotation改变了很多。先来看看官方的描述 http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/

知识点:

*UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterfaceOrientations and shouldAutorotate 2个方法来代替shouldAutorotateToInterfaceOrientation。注意:为了向后兼容iOS 4 and 5,还是需要在你的app里保留shouldAutorotateToInterfaceOrientation。

for ios 4 and 5, 如果没有重写shouldAutorotateToInterfaceOrientation,那么对于iphone来讲,by default是只支持portrait,不能旋转。

for ios 6, 如果没有重写shouldAutorotate and supportedInterfaceOrientations,by default, iphone则是"可以旋转,支持非upside down的方向",而ipad是"可以选择,支持所有方向"


example 1: for ios 4 and 5, iphone device, 若要"可以旋转,支持非upside down的方向",则可以在view controller里

  1. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
  2. return(interfaceOrientation!=UIDeviceOrientationPortraitUpsideDown);
  3. }

example 2: for ios 6, iphone device, 若要“不能旋转,只支持portait",则可以在view controller里

  1. -(BOOL)shouldAutorotate
  2. {
  3. returnNO;
  4. }

example 3: for ios 6, ipad device, 若要“可以旋转,只支持landscape",则可以在view controller里

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. returnUIInterfaceOrientationMaskLandscape;
  3. }
  4. -(BOOL)shouldAutorotate
  5. {
  6. returnYES;
  7. }


* 在iOS 4 and 5,都是由具体的view controller来决定对应的view的orientation设置。而在iOS 6,则是由top-most controller来决定view的orientation设置。

举个例子:你的app的rootViewController是navigation controller "nav", 在”nav"里的stack依次是:main view -> sub view > sub sub view,而main view里有一个button会present modal view "modal view".

那么for ios 4 and 5,在ipad里,如果你要上述view都仅支持横屏orientation,你需要在上面的main view, sub view, sub sub view, model view里都添加

  1. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
  2. return(interfaceOrientation==UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight);
  3. }

而对于iOS6, 由于是由top-most controller来设置orientation,因此你在main view, sub view, sub sub view里添加下面的代码是没有任何效果的,而应该是在nav controller里添加下列代码。而modal view则不是在nav container里,因此你也需要在modal view里也添加下列代码。

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. returnUIInterfaceOrientationMaskLandscape;
  3. }
  4. -(BOOL)shouldAutorotate
  5. {
  6. returnYES;
  7. }

注意:

*你需要自定义一个UINavigationController的子类for "nav controller",这样才可以添加上述代码。

* 和navigation controller类似,tab controller里的各个view的orientation设置应该放在tab controller里


for ios6的top-most controller决定orientation设置,导致这样一个问题:在 top-most controller里的views无法拥有不相同的orientation设置。例如:for iphone, 在nav controller里,你有main view, sub view and sub sub view,前2个都只能打竖,而sub sub view是用来播放video,可以打横打竖。那么在ios 4 and 5里可以通过在main view and sub view的shouldAutorotateToInterfaceOrientation里设置只能打竖,而在sub sub view的shouldAutorotateToInterfaceOrientation设置打竖打横即可。而在ios 6里则无法实现这种效果,因为在main view, sub view and sub sub view的orientation设置是无效的,只能够在nav controller里设置。那么你可能想着用下列代码在nav controller里控制哪个view打竖,哪个view打横

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. if([[selftopViewController]isKindOfClass:[SubSubViewclass]])
  3. returnUIInterfaceOrientationMaskAllButUpsideDown;
  4. else
  5. returnUIInterfaceOrientationMaskPortrait;
  6. }

是的,这样可以使得在main view and sub view里无法打横,而sub sub view横竖都行。但问题来了,如果在sub sub view时打横,然后back to sub view,那么sub view是打横显示的!

目前想到的解决方法只能是把sub sub view脱离nav controller,以modal view方式来显示。这样就可以在modal view里设置打横打竖,而在nav controller里设置只打竖。


* 说了那么多,其实如果你的app的所有view的orientation的设置是统一的,那么你可以简单的在plist file里设置即可,不用添加上面的代码。而如果你添加了上面的代码,就会覆盖plist里orientation的设置。


* in iOS 6, 当view controller present时,不会call willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods,只有在发生rotate的时候才会call


知识点:

*UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterfaceOrientations and shouldAutorotate 2个方法来代替shouldAutorotateToInterfaceOrientation。注意:为了向后兼容iOS 4 and 5,还是需要在你的app里保留shouldAutorotateToInterfaceOrientation。

for ios 4 and 5, 如果没有重写shouldAutorotateToInterfaceOrientation,那么对于iphone来讲,by default是只支持portrait,不能旋转。

for ios 6, 如果没有重写shouldAutorotate and supportedInterfaceOrientations,by default, iphone则是"可以旋转,支持非upside down的方向",而ipad是"可以选择,支持所有方向"


example 1: for ios 4 and 5, iphone device, 若要"可以旋转,支持非upside down的方向",则可以在view controller里

  1. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
  2. return(interfaceOrientation!=UIDeviceOrientationPortraitUpsideDown);
  3. }

example 2: for ios 6, iphone device, 若要“不能旋转,只支持portait",则可以在view controller里

  1. -(BOOL)shouldAutorotate
  2. {
  3. returnNO;
  4. }

example 3: for ios 6, ipad device, 若要“可以旋转,只支持landscape",则可以在view controller里

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. returnUIInterfaceOrientationMaskLandscape;
  3. }
  4. -(BOOL)shouldAutorotate
  5. {
  6. returnYES;
  7. }


* 在iOS 4 and 5,都是由具体的view controller来决定对应的view的orientation设置。而在iOS 6,则是由top-most controller来决定view的orientation设置。

举个例子:你的app的rootViewController是navigation controller "nav", 在”nav"里的stack依次是:main view -> sub view > sub sub view,而main view里有一个button会present modal view "modal view".

那么for ios 4 and 5,在ipad里,如果你要上述view都仅支持横屏orientation,你需要在上面的main view, sub view, sub sub view, model view里都添加

  1. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
  2. return(interfaceOrientation==UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight);
  3. }

而对于iOS6, 由于是由top-most controller来设置orientation,因此你在main view, sub view, sub sub view里添加下面的代码是没有任何效果的,而应该是在nav controller里添加下列代码。而modal view则不是在nav container里,因此你也需要在modal view里也添加下列代码。

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. returnUIInterfaceOrientationMaskLandscape;
  3. }
  4. -(BOOL)shouldAutorotate
  5. {
  6. returnYES;
  7. }

注意:

*你需要自定义一个UINavigationController的子类for "nav controller",这样才可以添加上述代码。

* 和navigation controller类似,tab controller里的各个view的orientation设置应该放在tab controller里


for ios6的top-most controller决定orientation设置,导致这样一个问题:在 top-most controller里的views无法拥有不相同的orientation设置。例如:for iphone, 在nav controller里,你有main view, sub view and sub sub view,前2个都只能打竖,而sub sub view是用来播放video,可以打横打竖。那么在ios 4 and 5里可以通过在main view and sub view的shouldAutorotateToInterfaceOrientation里设置只能打竖,而在sub sub view的shouldAutorotateToInterfaceOrientation设置打竖打横即可。而在ios 6里则无法实现这种效果,因为在main view, sub view and sub sub view的orientation设置是无效的,只能够在nav controller里设置。那么你可能想着用下列代码在nav controller里控制哪个view打竖,哪个view打横

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. if([[selftopViewController]isKindOfClass:[SubSubViewclass]])
  3. returnUIInterfaceOrientationMaskAllButUpsideDown;
  4. else
  5. returnUIInterfaceOrientationMaskPortrait;
  6. }

是的,这样可以使得在main view and sub view里无法打横,而sub sub view横竖都行。但问题来了,如果在sub sub view时打横,然后back to sub view,那么sub view是打横显示的!

目前想到的解决方法只能是把sub sub view脱离nav controller,以modal view方式来显示。这样就可以在modal view里设置打横打竖,而在nav controller里设置只打竖。


* 说了那么多,其实如果你的app的所有view的orientation的设置是统一的,那么你可以简单的在plist file里设置即可,不用添加上面的代码。而如果你添加了上面的代码,就会覆盖plist里orientation的设置。


* in iOS 6, 当view controller present时,不会call willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods,只有在发生rotate的时候才会call

根据原作 https://pan.quark.cn/s/459657bcfd45 的源码改编 Classic-ML-Methods-Algo 引言 建立这个项目,是为了梳理和总结传统机器学习(Machine Learning)方法(methods)或者算法(algo),和各位同仁相互学习交流. 现在的深度学习本质上来自于传统的神经网络模型,很大程度上是传统机器学习的延续,同时也在不少时候需要结合传统方法来实现. 任何机器学习方法基本的流程结构都是通用的;使用的评价方法也基本通用;使用的一些数学知识也是通用的. 本文在梳理传统机器学习方法算法的同时也会顺便补充这些流程,数学上的知识以供参考. 机器学习 机器学习是人工智能(Artificial Intelligence)的一个分支,也是实现人工智能最重要的手段.区别于传统的基于规则(rule-based)的算法,机器学习可以从数据中获取知识,从而实现规定的任务[Ian Goodfellow and Yoshua Bengio and Aaron Courville的Deep Learning].这些知识可以分为四种: 总结(summarization) 预测(prediction) 估计(estimation) 假想验证(hypothesis testing) 机器学习主要关心的是预测[Varian在Big Data : New Tricks for Econometrics],预测的可以是连续性的输出变量,分类,聚类或者物品之间的有趣关联. 机器学习分类 根据数据配置(setting,是否有标签,可以是连续的也可以是离散的)和任务目标,我们可以将机器学习方法分为四种: 无监督(unsupervised) 训练数据没有给定...
### 关于 nihui 开发的 ncnn-android-yolov5 项目 nihui 的 `ncnn-android-yolov5` 是一个基于 NCNN 推理框架的 Android 平台上的目标检测示例项目[^1]。该项目实现了 YOLOv5 模型在移动设备上的部署,旨在提供一种简单而高效的方式来展示如何将深度学习模型应用于实际场景。 以下是关于此项目的详细介绍: #### 1. **项目概述** 该 GitHub 仓库提供了完整的源码以及详细的文档说明,帮助开发者快速理解并集成 YOLOv5 到他们的 Android 应用程序中。通过使用 NCNN 这一高性能推理库,项目能够显著提升移动端的目标检测速度和效率。 #### 2. **主要功能模块** - **YOLOv5 模型支持**: 支持多种版本的 YOLOv5 模型加载与预测。 - **NCNN 后端加速**: 借助腾讯开源的 NCNN 深度学习推理框架完成模型计算操作。 - **跨平台兼容性**: 提供针对 ARM 架构进行了高度优化后的二进制文件以便适配大多数安卓手机硬件条件。 #### 3. **开发环境准备** 为了成功编译运行本项目, 用户需具备如下软硬件配置: - 安装最新版 Android Studio 及其配套 NDK 工具链. - 下载对应 ABI 版本 (armeabi-v7a 或 arm64-v8a) 的预训练权重参数包. 具体设置流程可以参照官方给出的相关指导链接或者查阅其他相似案例资料来补充完善个人工作区布局结构[^3]. #### 4. **核心代码解析** 下面是一段典型的 C++ JNI 函数定义片段用于处理来自 Java 层面调用请求: ```cpp extern "C" JNIEXPORT void JNICALL Java_com_example_ncnn_1android_1yolov5_MainActivity_detect(JNIEnv *env, jobject thiz, jlong matAddrRgba) { cv::Mat &rgba = *(cv::Mat *)matAddrRgba; // Convert image to BGR format required by model input cv::cvtColor(rgba, bgr, CV_RGBA2BGR); // Initialize net once per thread static ncnn::Net yolov5; if (!yolov5.loaded()) { yolov5.load_param("yolov5s.param"); yolov5.load_model("yolov5s.bin"); } ncnn::Extractor ex = yolov5.create_extractor(); ex.set_num_threads(4); const float mean_vals[3] = {0.f, 0.f, 0.f}; const float norm_vals[3] = {1 / 255.f, 1 / 255.f, 1 / 255.f}; ncnn::Mat in = ncnn::Mat::from_pixels_resize( bgr.data, ncnn::Mat::PIXEL_BGR, bgr.cols, bgr.rows, INPUT_WIDTH, INPUT_HEIGHT); in.substract_mean_normalize(mean_vals, norm_vals); ex.input("images", in); std::vector<Object> objects; detect_yolo(ex, objects); } ``` 上述代码展示了如何利用 OpenCV 将原始图片转换成适合输入给定神经网络的形式,并最终提取特征向量传递至后续逻辑单元继续加工分析过程. #### 5. **常见问题解答** 如果遇到某些特定错误提示比如找不到 so 动态库路径等问题,则可能是因为未正确指定本地依赖项位置关系所致;此时建议重新审视 build.gradle 文件中的 externalNativeBuild 节点内容是否匹配当前系统的实际情况调整相应字段值即可解决此类状况[^5]. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值