iRe*_*_85 10 iphone objective-c uiwebview
我的iPhone应用程序是一个纵向导向的应用程序,在我的应用程序中,我有UITableView一个UIWebView在第一个UITableCell.该UIWebView节目嵌入YouTube视频.当我点击视频播放时,它进入全屏模式.我需要做的是,允许用户旋转他们的设备并以横向模式播放视频.然后,当视频停止时,只允许再次使用肖像.我设置为在视频进入全屏并且全屏显示时收听通知.但我不知道如何以编程方式允许用户旋转界面方向.
所以我通常在传递通知时调用了2个方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
-(void)youTubeStarted:(NSNotification *)notification{
// Entered fullscreen code goes here.
}
-(void)youTubeFinished:(NSNotification *)notification{
// Left fullscreen code goes here.
}
Run Code Online (Sandbox Code Playgroud)
我会在这两种方法中放置什么来仅在视频播放期间改变方向?
iRe*_*_85 19
我想到了.在我的2种方法中:
-(void)youTubeStarted:(NSNotification *)notification{
// Entered Fullscreen code goes here..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = YES;
}
-(void)youTubeFinished:(NSNotification *)notification{
// Left fullscreen code goes here...
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = NO;
//CODE BELOW FORCES APP BACK TO PORTRAIT ORIENTATION ONCE YOU LEAVE VIDEO.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
Run Code Online (Sandbox Code Playgroud)
我通过设置AppDelegate的BOOL属性在上述方法中访问了我的App委托.然后我在AppDelegate.m中调用了下面的应用程序方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
if (self.fullScreenVideoIsPlaying == YES) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
}
Run Code Online (Sandbox Code Playgroud)
这self.fullScreenVideoIsPlaying是BOOL我在AppDelegate.h文件中设置的属性.
我希望这可以帮助别人,我失去了5个小时.
| 归档时间: |
|
| 查看次数: |
5433 次 |
| 最近记录: |