Tag: 设备方向

以编程方式在viewdidload中设置方向不起作用

我已经创build了一个iPad的应用程序,其中的主屏幕只能在肖像模式下显示。 所以我已经在viewdidload中使用了下面的代码。 [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]; 但它不工作。 我正在使用ios 7 xcode 5.如果我从横向模式打开我的应用程序,它会自动转到肖像模式。 但我越来越像这样: 但应该是这样的: 任何人都可以帮我解决这个问题。 提前致谢。

修复iOS Safari的“deviceorientation”事件不规范?

我一直在使用'deviceorientation'作为我的项目 ,当在iPhone / iPad上testing时,它在横向模式下performance正常,但在纵向模式下有不规则性。 以下是重复的步骤: 以纵向模式在iPad / iPhone上打开此JSFiddle – 移动设备,就好像你正在通过摄像机看,看着你的脚,看着地平线,仰望天空 event.beta将从0 – > +/- 90 – > 0 注意event.gamma在设备到达地平线的时候跳跃,当event.beta = 90时 问题1:如何调整这种行为? 问题2:从这个方向,从地面到天空,是否有任何方法可以获得确定的值(例如0-180)? HTML <b>e.alpha :</b> <span id='alpha'></span><br/> <b>e.beta :</b> <span id='beta'></span><br/> <b>e.gamma :</b> <span id='gamma'></span><br/> JS function deviceOrientationHandler(e){ var a = document.getElementById('alpha'); var b = document.getElementById('beta'); var g = document.getElementById('gamma'); a.innerText = e.alpha; b.innerText […]

由NSNotificationCenter给出的键盘大小

我想从UISearchBar调用的键盘上添加一个accessoryView。 由于UISearchBar没有实现这个属性,我刚刚创build了一个工具条。 继苹果关于此事的文档之后,我决定使用通知中心不仅要知道何时调用键盘,还要知道键盘的大小,这取决于方向。 我已经按照文档上的例子,并在keyboardWasShown方法,我调用一个animation,将显示在键盘上的工具栏。 像这样的东西: -(void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary *info=[aNotification userInfo]; CGSize keyboardSize=[[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; NSLog(@"width: %.1f; heigth: %.1f", keyboardSize.width, keyboardSize.height ); [self showAccessoryView:keyboardSize.height]; } 而在animation上,我这样设置工具栏的框架: self.auxiliaryKeyboardBar.frame=CGRectMake(0, self.view.frame.size.height-(44+kbh), self.view.frame.size.width, 44); 其中44是工具栏的静态高度,kbh是从上面的方法传递的keyboard.size.heigth。 我观察到的问题是由userInfo Dictionary给出的键盘大小总是被引用到纵向方向。 所以,NSLog的纵向定位是: width: 320.0; heigth: 216.0 width: 320.0; heigth: 216.0 ,没关系 但是当我改变方向为风景,我打电话给键盘,NSLog如下: width: 162.0; heigth: 480.0 width: 162.0; heigth: 480.0 ,这使得工具栏超出了范围。 所以,我最终在调用animation之前添加了一个条件,例如: if ([self […]

防止AlertView自动旋转

我的应用程序的启动页面设置为肖像只有这一点点的代码: – (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait ; } 当应用程序启动时出现用户名和密码input的UIAlertView 。 显示它的方法从viewWillAppear调用。 这对iOS6工作正常,但自iOS7以来,如果我将设备切换到横向,主视图保持纵向,但警报视图和键盘旋转到横向。 另一个奇怪的怪癖是,当我切换回肖像时,只有键盘切换回来(以截短的forms),将警报冻结在横向模式下: 谁能告诉我如何防止这个? -编辑- 自动替代码在另一个类别中被调用: @implementation UINavigationController (Orientation) -(NSUInteger)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations]; } -(BOOL)shouldAutorotate { if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) return NO; else return YES; } @结束 -EDIT 2- 我也尝试在UIAlertView上创build一个类别,但它从来没有被称为: @implementation UIAlertView (Orientation) -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } -(BOOL)shouldAutorotate { return NO; } -EDIT […]

iOS:禁用子视图的自动旋转

我有支持方向更改的iPad应用程序的嵌套视图层次结构。 它看起来与以下类似。 UIViewController UIView – UIView – UIImageView (disable rotation) – UIImageView – UIView (disable rotation) – UIView – UIView … 我想locking一些子视图的方向,同时允许其他人自动旋转和resize。 我似乎无法弄清楚如何做到这一点。 一种方法似乎是在willAnimateRotationToInterfaceOrientation:手动旋转子视图。 鉴于SDK正在执行旋转,我只是将其撤销,这并不是特别有吸引力。 有没有办法简单地禁用方向更改子视图或其他方法来重构我的层次结构?