UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法

UIDeviceOrientation 设备方向 & UIInterfaceOrientation 控制器方向     为什么写这篇博客呢,因为在封装播放器avplayer的过程中,横屏竖屏的旋转让我纠结了好一会,写的明明是正确的,就是因为Xcode有没有勾选横屏出现了旋转问题,小细节决定大问题呀。接下来细说 UIDeviceOrientation 和 UIInterfaceOrientation 的区别与联系一、UIDeviceOrientation设备方向UIDeviceOrientation设备方向,... 阅读详情
UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置

UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置





判断设备现在的方向:
C代码  收藏代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
{  
    //宣告一個UIDevice指標,並取得目前Device的狀況  
    UIDevice *device = [UIDevice currentDevice] ;   

    //取得當前Device的方向,來當作判斷敘述。(Device的方向型態為Integer)  
    switch (device.orientation) {  
        case UIDeviceOrientationFaceUp:  
        NSLog(@"螢幕朝上平躺");  
            break;  

        case UIDeviceOrientationFaceDown:  
        NSLog(@"螢幕朝下平躺");  
            break;  

        //系統無法判斷目前Device的方向,有可能是斜置   
        case UIDeviceOrientationUnknown:  
        NSLog(@"未知方向");  
            break;  

        case UIDeviceOrientationLandscapeLeft:  
        NSLog(@"螢幕向左橫置");  
            break;  

        case UIDeviceOrientationLandscapeRight:  
        NSLog(@"螢幕向右橫置");  
            break;  

        case UIDeviceOrientationPortrait:  
        NSLog(@"螢幕直立");  
            break;  

        case UIDeviceOrientationPortraitUpsideDown:  
        NSLog(@"螢幕直立,上下顛倒");  
            break;  

        default:  
        NSLog(@"無法辨識");  
            break;  
    }  

    // Return YES for supported orientations  
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向  
}  

或者
C代码  收藏代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
{  
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;  
    if (UIDeviceOrientationIsLandscape(deviceOrientation)) NSLog(@"横向");      
    else if(UIDeviceOrientationIsPortrait(deviceOrientation)) NSLog(@"纵向");  

    // // Return YES for supported orientations  
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向  
}  

Portrait 表示 纵向,Landscape 表示 横向。

C代码  收藏代码
typedef enum {  
    UIDeviceOrientationUnknown,  
    UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom  
    UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top  
    UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right  
    UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left  
    UIDeviceOrientationFaceUp,              // Device oriented flat, face up  
    UIDeviceOrientationFaceDown             // Device oriented flat, face down  
} UIDeviceOrientation;  

C代码  收藏代码
typedef enum {  
    UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,  
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,  
    UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,  
    UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft  
} UIInterfaceOrientation;  

C代码  收藏代码
#define UIDeviceOrientationIsPortrait(orientation)  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)  
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)  

上面是重要的源代码,已经解释的非常清楚。UIDeviceOrientationIsPortrait(orientation) 跟  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown) 完全是一个意思。
UIDeviceOrientation与UIinterfaceOrientation以及屏幕旋转的方式 在日常开发过程中,经常会遇到转屏的需求,最近遇到一个转屏相关的bug,顺带着总结下iOS端实现转屏需要做的事情。 首先需要明确两个概念,设备方向(UIDeviceOrientation)和视图方向(UIInterfaceOrientation) UIDeviceOrientation: 不受锁定屏幕方向的影响,通过[UIDevice currentDevice].orient 阅读详情

相关推荐

【Spreadsheet】香港规范结构设计电子表格库开发方案

深入理解香港本地规范特点和要求结合国际先进标准(Eurocode) 的技术内容考虑香港地理环境特殊性 (台风、地质等)建立完善的质量控制体系保持持续更新维护的能力。

hmywillstronger的博客 1361

UIDeviceOrientation和UIInterfaceOrientation

http://www.cocoachina.com/articles/19808

天道酬勤 1522

AD20 Channel-Offset Error 解决办法

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言AD20 PCB相同电路模块ROOM格式复用时出现 Channel-Offset Error 解决办法一、问题现象二、解决办法 前言 AD20 PCB相同电路模块ROOM格式复用时出现 Channel-Offset Error 解决办法 一、问题现象 我们经常在使用Room格式快速布局相同模块电路时出现以下问题, 二、解决办法 相同模块电路PCB布局复制的过程网上有很多,这里不再做赘述,步骤都差不多,只说问题根源; 1:.

m0_47201213的博客 7623

ios 设备方向判断

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 博客分类: IOS / Objective-C UIDeviceOrientation 是机器硬件的当前旋转方向 这个你只能取值 不能设置 UIInterfaceOrientation 是你程序界面的当前旋转方向 这个可以设置 ...

abv10122的博客 378

POSS-NH2:氨基化笼型聚半倍硅氧烷的合成与应用探索

本文详细介绍了氨基化笼型聚半倍硅氧烷(POSS-NH2)的合成方法与应用。通过水解缩合与官能团转化两种主流路线,可制备出这种关键的纳米增强材料。其核心价值在于通过表面的氨基与树脂基体形成化学键合,从而显著提升复合材料的热稳定性和机械性能。文章以环氧树脂改性为例,展示了POSS-NH2在航空航天、电子封装等高性能领域的应用潜力。

grpc6streamer的博客 499

2022-04-06 RK3566 上调试百兆以太网卡YT8512C 调试记录

一、原理图 二、dts &gmac1_clkin{ clock-frequency = <50000000>; status = "okay"; }; &gmac1 { phy-mode = "rmii"; clock_in_out = "input"; snps,reset-gpio = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>; snps,reset-active-low; sn...

海月汐辰 1万+

UIDeviceOrientation和UIInterfaceOrientation屏幕旋转的用法

1. UIDeviceOrientation是设备的方向,只能读,不能修改 typedef NS_ENUM(NSInteger, UIDeviceOrientation) { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, // Device oriented vertically, ho

jpcfei的专栏 1万+

致远OA系统表单相关操作记录(一)

致远OA系统表单相关操作

weixin_59666050的博客 6102

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)

UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置   判断设备现在的方向: C代码   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterface

huifeidexin_1的专栏 9118

【数据挖掘】心跳信号分类预测 之 特征工程 —— 学习笔记(三)

三、特征工程 3.1 看书 常言道,“巧妇难为无米之炊”。在 ML 中,数据和特征将作“米”,模型和算法则为“妇”。若无数量充足的数据、良好表示的特征,再强大的模型也难以得到满意的结果 (garbage in,garbage out)。对于 ML 问题,数据和特征往往决定了结果的上限,而模型、算法的选择及优化则是在逐步接近该上限。 特征工程,顾名思义,是对原始数据进行一系列工程处理,将其提炼为特征,作为输入供算法和模型使用。在本质上,特征工程是一个表示和展现数据的过程。在实际中,特征工程旨在去除...

闻韶 3358

061、LQR(线性二次型调节器)控制基础

本文介绍了LQR(线性二次型调节器)控制在飞控系统中的应用。作者通过一次四旋翼炸机事故引出PID控制的局限性,详细讲解了LQR的数学原理、权重矩阵的物理意义以及实际工程实现方法。文章对比了LQR与PID的控制效果,指出LQR在鲁棒性方面的优势,同时也分析了其存在稳态误差等缺点。最后总结了LQR在飞控中的适用场景,建议将LQR与PID结合使用,并预告了下一章将讨论带积分项的LQI控制。全文包含具体案例、代码实现和调参经验,为飞控算法开发者提供了实用指导。

2401_88858637的博客 720

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)  和 IOS6屏幕旋转详解

1. UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 博客分类:  IOS / Objective-C UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向

qq515383106的专栏 8636

刷机维修进阶教程-----oppo机型 一加 7pro 修复基带 更改参数 实例详细步骤解析

通过课程基本可以了解 1-----oppo机型与一加7机型更改参数的具体步骤解析 2------了解oppo机型开启diag端口的具体步骤 3-----了解一加7这些机型改参数常识 。可以借鉴参考用于其他机型 4-----了解手机基带分区与基带辅助分区的作用 5-----机型参数能读取到 但不能写这种情况如何操作

小马哥的专栏 1478

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)

UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置   判断设备现在的方向: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr...

Just Code 153

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

iOS UIDeviceOrientation 和 UIInterfaceOrientation 用法

UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置   判断设备现在的方向: C代码   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrienta...

iOS_Chen的专栏 617

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UIDeviceOrientation 和 UIInterfaceOrientation

UIDeviceOrientation 和 UIInterfaceOrientation 有时候,我们处理自动布局时,需要获取到屏幕旋转方向: 以下为本人亲测: UIInterfaceOrientation: 我们需要在- (void)viewDidLoad或其他方法中添加观察者,检测屏幕的旋转: // 监听状态栏旋转方向,即屏...

IF 239

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的方向

UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置   判断设备现在的方向:   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfac

cactusz的博客 257
上一篇: iOS短信验证码倒计时Button的实现
下一篇: iOS开发-解决AVAudioRecorder录音文件无法保存的问题
CAPT_DavidLee
博客等级 码龄11年 1粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值