标签: uiinterfaceorientation

如何将嵌入的YouTube视频旋转到横向模式

我正在使用以下嵌入代码在IOS上嵌入我的YouTube视频

- (NSString*)embedYouTube:(NSString*)youtube_id frame:(CGRect)frame {  
   NSString* embedHTML = @"\
   <html><head>\
   <style type=\"text/css\">\
   body {\
   background-color: transparent;\
   color: white;\
   }\
   </style>\
   </head><body style=\"margin:0\">\
   <iframe src=\"http://www.youtube.com/embed/%@?rel=0\" frameborder=\"0\" allowfullscreen width=\"%0.0f\" height=\"%0.0f\"></iframe>\
   </body></html>"; 
   NSString *html = [NSString stringWithFormat:embedHTML, youtube_id, frame.size.width, frame.size.height];

   return html;
}

//code to embed video
NSString *contentHTML;
if (currentAnswer.youtube_id != nil) {
    contentHTML = [self embedYouTube:currentAnswer.youtube_id frame:CGRectMake(CELL_TEXT_LEFT_MARGIN + CELL_AVATAR_WIDTH + CELL_SPACING, currentYAxisValue, CELL_YOUTUBEVIEW_WIDTH, CELL_YOUTUBEVIEW_HEIGHT)];
}

[webView loadHTMLString: contentHTML baseURL:nil];
Run Code Online (Sandbox Code Playgroud)

当我播放视频时,它只播放在potrait模式而不是横向模式.这是由于'iframes'的限制吗,有什么方法可以解决这个问题吗?

embed youtube landscape uiinterfaceorientation ios

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

等了10秒后没能回来.主运行循环模式:kCFRunLoopDefaultMode void SendDelegateMessage(NSInvocation*):委托

嗨,我正在使用核心图标头开发IOS应用程序.我有不同的UI用于风景和肖像.当我试图修改UIview的帧时,取向变化我在等待10秒后无法返回.主运行循环模式:kCFRunLoopDefaultMode void SendDelegateMessage(NSInvocation*):delegate.有人可以建议我做什么.

core-plot uiinterfaceorientation ios

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

将视图从横向转换为纵向?

我已经开发了横向模式的应用程序,现在客户端要求在横向和纵向模式下构建.

如何将横向视图转换为纵向视图?

现在我将此代码用于Landscape View:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{

 return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

 }
Run Code Online (Sandbox Code Playgroud)

请帮我....

预付谢谢:)

cocoa-touch objective-c uiinterfaceorientation ios

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

setStatusBarOrientation:animated:在iOS 6中不起作用

在用户完成观看视频(允许以横向模式观看)之前,我已经使用此代码强制将方向更改回纵向,然后将视频视图控制器从导航控制器上弹出:

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];

//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
Run Code Online (Sandbox Code Playgroud)

这完美地工作直到iOS 5.1.1.我甚至试图在另一篇文章中阅读后使用新的现有/解除方法,现在应该使用这些方法:

[self presentViewController:mVC animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
Run Code Online (Sandbox Code Playgroud)

问题是它根本不起作用.将视频查看器旋转到横向然后弹出后,我的设置视图(表格视图控制器)返回,但也处于横向模式.

我甚至试过过这里的小费

"该setStatusBarOrientation:animated:方法并未完全弃用.但是,现在只有当supportedInterfaceOrientations最顶层的全屏视图控制器的方法返回0时,它才有效.这使得确保状态栏方向与调用者手中一致的责任."

所以,我尝试了设置标志,强制supportedInterfaceOrientationsreturn 0(调用上面的第一个代码块之前),但它也不起作用.

有人有解决方案吗?感谢您的时间和精力.

cocoa-touch objective-c uiinterfaceorientation autorotate ios6

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

如何在仅限肖像的应用程序中使用MPMovieViewController播放风景视频

我的应用程序支持的界面方向是纵向和上下颠倒.但是,播放视频时,我希望它能够播放全屏风景.目前使用此代码,即使设备旋转,它也只播放肖像:

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self presentMoviePlayerViewControllerAnimated:player];
Run Code Online (Sandbox Code Playgroud)

如何强制它进入横向模式?

mpmovieplayercontroller uiinterfaceorientation ios

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

为纵向和横向模式获得相同的屏幕宽度和高度

我用这段代码来获取屏幕宽度和屏幕高度,

    float scaleFactor = [[UIScreen mainScreen] scale];
    CGRect screen = [[UIScreen mainScreen] bounds];
    CGFloat widthInPixel = screen.size.width * scaleFactor;
    CGFloat heightInPixel = screen.size.height * scaleFactor;

    NSLog(@"%f",widthInPixel);
    NSLog(@"%f",heightInPixel);
Run Code Online (Sandbox Code Playgroud)

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    NSLog(@"screenBounds W %f",screenBounds.size.width);
    NSLog(@"screenBounds H %f",screenBounds.size.height);
Run Code Online (Sandbox Code Playgroud)

但它在纵向和横向模式下显示相同的宽度= 768和高度= 1024.

objective-c orientation uiinterfaceorientation ios

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

在 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
查看次数

通过仅纵向视图控制器呈现仅横向视图控制器时,状态栏隐藏

我有一个导航控制器,持有一个只支持纵向的视图控制器:

在此输入图像描述

这提供了一个仅支持横向的全屏视图控制器:

在此输入图像描述

不幸的是,在转换期间,呈现视图控制器上的状态栏被移除,这使得内容在转换开始之前急剧上升.我已经实现了自定义淡入淡出过渡以使效果明显:

在此输入图像描述

请注意,状态栏不存在.这是自定义转换开始之前完成的,没有动画,所以即使我在转换开始之前拍摄快照并将其添加到容器视图中,您仍然会暂时看到缩小的导航栏.

有一种非可怕的方法来解决这个问题吗?我不想在转换之外添加快照(比如这个答案).

我已尝试将演示文稿样式设置为自定义而不是全屏,但这不会使设备处于纵向方向.使用自定义呈现样式使设备保持横向方向的解决方案也是可以接受的.

有一个示例项目演示问题在这里

uiinterfaceorientation ios uistatusbar

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

强迫方向改变有时不起作用

在我的应用程序中按下某个按钮时,视图应该从纵向更改为横向.当用户返回时,视图控制器应该更改回肖像.但有时方向不会改变或使用错误的视图框架.

这是我的代码

-(void)btnSignClicked:(CustomSignButton *)btn {
    isSignButtonClicked = true;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0) {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
    else
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
    }
    selectedWaiverId = btn.customTag;

    SignatureView *obj = [[SignatureView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) delegate:self]; // Most of time got size (568,320) but some time i got (320,568), Don't know why
    [self.view addSubview:obj];
}

#pragma mark - SIGNATUREVIEW DELEGATE
-(void)removeSignatureView:(SignatureView *)signatureView {
    isSignButtonClicked = false;

    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0)
    {
        NSNumber *value …
Run Code Online (Sandbox Code Playgroud)

objective-c uiinterfaceorientation ios ios8

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

iOS 9中的强制视图控制器方向

我正在制作一个摄影应用程序,允许以肖像或风景拍摄照片.由于项目的要求,我不能让设备方向自动旋转,但确实需要支持旋转.

使用以下定位方法时:

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if self.orientation == .Landscape {
        return UIInterfaceOrientationMask.LandscapeRight
    } else {
        return UIInterfaceOrientationMask.Portrait
    }
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    if self.orientation == .Landscape {
        return UIInterfaceOrientation.LandscapeRight
    } else {
        return UIInterfaceOrientation.Portrait
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以在启动时正确设置旋转.通过更改方向值并调用UIViewController.attemptRotationToDeviceOrientation()我能够支持旋转到新的所需界面.但是,此旋转仅在用户实际移动其设备时发生.我需要它自动发生.

我可以调用:UIDevice.currentDevice().setValue(targetOrientation.rawValue, forKey: "orientation")强制更改,但这会导致其他副作用,因为UIDevice.currentDevice().orientation只返回该点的setValue.(而且非常脏)

有什么我想念的吗?我已经研究过关闭并启动一个新的视图控制器,但这有其他问题,例如在解除时立即出现UI故障并立即呈现新的视图控制器.

编辑:

以下方法对我不起作用:

编辑2:

对潜在解决方案的思考

  1. 直接设置方向(带setValue)并处理iOS 9上出现的所有副作用(不可接受)

  2. 我可以使用当前的解决方案并指示用户需要旋转设备.设备物理旋转后,UI会旋转,然后正确锁定到位.(差的UI)

  3. 我可以找到一种解决方案,强制刷新方向并在没有物理操作的情况下旋转.(我在问什么,并寻找)

  4. 手工完成所有工作.我可以纵向或横向锁定界面,并手动旋转和调整容器视图的大小.这是"脏"的,因为它放弃了所有大小类自动布局功能,并导致更重的代码.我试图避免这种情况.

iphone uiinterfaceorientation ios

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