标签: uideviceorientation

UIDeviceOrientationFaceUp - 如何区分肖像和风景?

我试图找出设备是纵向还是横向模式.如果设备没有朝上,我的代码工作得很好.如果它面朝上(和方向== 5),它将无法区分肖像和风景.如果UIDeviceOrientation是FaceUp,有没有在风景/肖像方面确定"方向"?

我的代码:

UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

NSLog(@"orientation: %d", interfaceOrientation);

if (interfaceOrientation == UIDeviceOrientationIsLandscape(interfaceOrientation)) {
    NSLog(@"LANDSCAPE!!!");
}

if (interfaceOrientation == UIDeviceOrientationIsPortrait(interfaceOrientation)) {
    NSLog(@"PORTRAIT!!!");
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ipad landscape-portrait uideviceorientation

19
推荐指数
2
解决办法
8574
查看次数

当iphone设备方向朝上/朝下时,我可以判断它是风景还是肖像?

我得到了这个代码,如果设备是横向左/右或倒置它旋转并显示另一个视图控制器.但如果它朝上或面朝下,那么如何判断它是横向模式还是纵向?因为我只想面朝上或朝下并以横向模式旋转

    - (void)viewDidAppear:(BOOL)animated
    {
        UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];
        NSLog(@"orientation %d", orientation);
        if ((orientation == 2) || (orientation == 3) || (orientation == 4))
        {

            [self performSegueWithIdentifier:@"DisplayLandscapeView" sender:self];
            isShowingLandscapeView = YES;
    }
}
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller ios uideviceorientation

18
推荐指数
2
解决办法
7288
查看次数

获取设备当前方向(App Extension)

如何在App Extension中获取设备当前方向,我尝试了以下两种方法但没有成功.

  1. 它总是返回UIDeviceOrientationUnknown

    [[UIDevice currentDevice] orientation]
    
    Run Code Online (Sandbox Code Playgroud)
  2. 它显示红色消息,'sharedApplication'在iOS上不可用(App Extension)

    [[UIApplication sharedApplication] statusBarOrientation];
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我还添加了一个观察者,但它没有被调用.

    [[NSNotificationCenter defaultCenter] addObserver:self.view selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
    
    
    
    - (void)notification_OrientationWillChange:(NSNotification*)n
    {
       UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue];
    
        if (orientation == UIInterfaceOrientationLandscapeLeft)
           [self.textDocumentProxy insertText:@"Left"];
        if (orientation == UIInterfaceOrientationLandscapeRight)
           [self.textDocumentProxy insertText:@"Right"];
    }
    
    Run Code Online (Sandbox Code Playgroud)

那么现在如何才能获得当前的设备定位.

keyboard objective-c ios uideviceorientation ios-app-extension

16
推荐指数
5
解决办法
1万
查看次数

禁用以纵向AVFoundation以外的任何方向拍摄图像

AVFoundation用来显示相机.

我想防止相机本身旋转,这样观看者只能以纵向方式看到相机,而且图像只能以人像模式拍摄.

我定义Supported Interface Orientation为仅支持肖像,视图本身仅在纵向模式下显示,但不是相机 - 正在按设备方向旋转

如何强制AVFoundation显示相机并仅像UIViewController一样以纵向捕捉图像?

我设置相机的代码:

AVCaptureVideoPreviewLayer* lay = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.sess];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[lay setFrame:bounds];
if ([lay respondsToSelector:@selector(connection)])
 {
   if ([lay.connection isVideoOrientationSupported])
   {
      [lay.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
    }
 }
 [lay setVideoGravity:AVLayerVideoGravityResizeAspectFill];
 [viewLayer insertSublayer:lay below:[[viewLayer sublayers] objectAtIndex:0]];
 self.previewLayer = lay;
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c avfoundation uideviceorientation

12
推荐指数
1
解决办法
3032
查看次数

方向更改时更改或禁用iPhone旋转动画

当屏幕方向从横向更改为纵向时,如何更改或禁用旋转动画,反之亦然?

iphone objective-c uideviceorientation

8
推荐指数
2
解决办法
9352
查看次数

UIDavigationController推送后[UIDevice currentDevice] .orientation == UIDeviceOrientationUnknown

这是一个比任何事情更多的观察,因为我似乎找到了一个解决方法......

当它在一个已被推送到UINavigationController堆栈的控制器中时,下面的代码无法工作.在这种情况下[UIDevice currentDevice].orientation一直回归UIDeviceOrientationUnknown.

-(void)layoutAccordingToOrientation {
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation);
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        :
        _detailToolbar.frame = CGRectMake(0, 660, 1024, 44);
    } else {
        :
        _detailToolbar.frame = CGRectMake(0, 916, 768, 44);
    }
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self layoutAccordingToOrientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

以下调用取得:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)

要解决这个UIDeviceOrientationUnknown问题,我现在使用以下代码:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
    etc.
} else {
    etc.
}
Run Code Online (Sandbox Code Playgroud)

......每次都有效.

尽管如此,我仍然不明白为什么第一个变体在推送视图控制器的上下文中不起作用.想法有人吗?这只是一个错误吗?

iphone uinavigationcontroller uiinterfaceorientation uideviceorientation

7
推荐指数
1
解决办法
5432
查看次数

当方向锁定打开且应用程序仅支持纵向时,如何检测设备方向

我遇到的问题是,当用户使用我们的应用程序拍照时AVCaptureSession,我无法确定他们是以纵向还是横向模式拍摄照片.我们的应用程序仅支持Portrait,我在使用手机时保持方向锁定,因此我正在尝试构建一个解决方案,假设其他人也可以这样做.

我查看了使用[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]但是当Orientation Lock打开时,没有收到任何通知.我知道此功能是可行的,因为当我的手机启用了方向锁定时,基本相机应用和Google环聊应用中的相机可以检测到旋转(取消和Flash按钮上的动画很明显).

我最好使用加速度计并检测手机旋转的角度?一个老的答案,检测iPhone的屏幕方向,很明显检测到这种方式的角度很容易做到(显然适应使用Core Motion而不是UIAccelerometer的答案),但我很好奇是否有另一种方法可以做它.

objective-c accelerometer ios core-motion uideviceorientation

7
推荐指数
1
解决办法
934
查看次数

在 Swift 中强制定向后恢复自动旋转

在我的 iPhone 应用程序中,我有一个我只想以纵向模式显示的视图。当导航到该视图时,它应该自动显示在纵向视图中。当导航离开时,方向应该变回原来的状态,或者,如果设备方向发生了变化,则适应它。我可以找到有关强制定向和防止自动旋转的信息。在离开该视图后,我找不到有关如何改回正确方向的任何信息。

所以我的想法是

  1. 保存初始方向(存储在currentOrientation
  2. 订阅方向更改事件以在内容锁定为纵向时跟踪方向更改(更新currentOrientation
  3. 离开视图时,使用该currentOrientation值恢复正确的方向。

编辑(现已删除代码):除了它不起作用之外,这是一种危险的方法,因为它广泛使用了不受支持的 API。


编辑:

我相信这个问题现在可以归结为以下几点:

  1. 是否有记录的、受支持的方法来强制界面方向独立于设备方向setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: "orientation")已在 SO 和其他地方多次推荐,但它确实似乎是不受支持的 hack。

  2. 是否有记录的、受支持的方式将界面方向更新为设备方向?这将需要从另一个视图中的强制界面方向“恢复”,而不必通过来回转动设备来触发自动旋转。

支持的是supportedInterfaceOrientations()shouldAutorotate()。但是这些只会在设备转到该位置后锁定 interfaceOrientation。它们不能防止错误的初始方向。

与此类似的问题有很多,可见此问题的设置并不少见,但目前使用支持的方法还没有令人满意且完整的解决方案。

uiinterfaceorientation ios uideviceorientation swift

6
推荐指数
1
解决办法
3687
查看次数

upSideDown iPhone方向在iOS 6中不起作用?

希望你会好起来,尽力而为.

upSideDown Orientation在我iOS 6身上遇到了问题,而我认为我做的一切都很完美,但我不知道为什么它不适合我.我和你分享我的问题,以便得到任何解决方案.

到目前为止我做了什么:

a)在xcode项目摘要选项卡中,我启用了所有4个方向.

b)我在所有控制器类中都添加了一段代码(如下所示).

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

但仍然upSideDown Orientation无法正常工作

谢谢你的期待.

objective-c uiinterfaceorientation uideviceorientation ios6 xcode4.5

5
推荐指数
1
解决办法
3860
查看次数

如何在应用程序部署信息纵向锁定时手动设置设备方向?

我不希望我的应用程序被美化,并始终是porttrait.So我使我的应用程序部署信息只设置肖像.但是当我需要在我的应用程序中显示任何图像或视频时,我需要横向模式以便更好地显示.

我可以通过检测设备方向的变化

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:
        /*  */
        break;

    case UIDeviceOrientationPortraitUpsideDown:
        /*  */
        break;
    case UIDeviceOrientationLandscapeLeft:
       /*  */
       break;

    case UIDeviceOrientationLandscapeRight:
       /*  */
       break;
    default:
        break;
};
}
Run Code Online (Sandbox Code Playgroud)

但是,即使应用程序部署信息纵向被锁定,如何手动更改设备方向?

不起作用

NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
Run Code Online (Sandbox Code Playgroud)

iphone portrait ios landscape-portrait uideviceorientation

5
推荐指数
2
解决办法
9832
查看次数