I have got a TableViewController which is only for PortraitMode. Now I want to play a video when a cell is touched.
In my App Delegate I am working with the method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
NSLog(#"ja1");
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[UINavigationController class]]) {
NSLog(#"ja2");
// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];
// is at the top?
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
NSLog(#"ja3");
return UIInterfaceOrientationMaskAllButUpsideDown;
// or it's presented from the top?
} else if ([[nc.topViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
NSLog(#"ja4");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return UIInterfaceOrientationMaskPortrait;
}
to make it possible to turn to landscape while watching the video.
I show an instance of MPMoviePlayerViewController from my TableView
- (void)playVideo {
NSURL *movieURL = [NSURL URLWithString:MYURL];
MPMoviePlayerViewController *c = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:c
name:MPMoviePlayerPlaybackDidFinishNotification
object:c.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:c.moviePlayer];
// Set the modal transition style of your choice
c.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Present the movie player view controller
[self presentViewController:c animated:YES completion:^{}];
// Start playback
[c.moviePlayer prepareToPlay];
[c.moviePlayer play];
}
Now I have the problem, that when I dismiss the MPMoviePlayerViewController in landscape mode I want to rotate it back to Portrait mode. But my MasterViewController (=TableView) is still in landscape mode.
Can you help me out!
Implement following orientation methods in your MasterViewController. which will make your MasterViewController to stay portrait.
- (BOOL)shouldAutorotate{
return false;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Related
I am automating IOS app test cases using Appium. I have a scenario in which I have to identify.. i am on which screen so that I can close the screen
In broader view , we have a inapp notification in our app which get open in random way.
So I can handle these condition if I would be able to identify the current screen.
I handle the same thing in Android using driver.currentActivity method
I need the some kind of same method for IOS apps
you get top most view controller by using below method
+ (UIViewController*) topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
Or if you have navigation or UIabbar controller then use below method to get visible view controller
- (void)applicationWillResignActive:(UIApplication *)application
{
UIViewController *vc = [self visibleViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)visibleViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil)
{
return rootViewController;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self visibleViewController:lastViewController];
}
if ([rootViewController.presentedViewController isKindOfClass:[UITabBarController class]])
{
UITabBarController *tabBarController = (UITabBarController *)rootViewController.presentedViewController;
UIViewController *selectedViewController = tabBarController.selectedViewController;
return [self visibleViewController:selectedViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [self visibleViewController:presentedViewController];
}
Im creating an iPad application that should be supported both landscape and portrait. I have set root view controller in AppDelegate like this. This view is my Splash screen view.
Inside
`
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
//Do what you want in Landscape Left
viewController1=[[SplashLandscapeViewController alloc] initWithNibName:#"SplashLandscapeViewController" bundle:nil];
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
//Do what you want in Landscape Right
viewController1=[[SplashLandscapeViewController alloc] initWithNibName:#"SplashLandscapeViewController" bundle:nil];
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
//Do what you want in Portrait
viewController1=[[SplashLandscapeViewController alloc] initWithNibName:#"SplashViewController" bundle:nil];
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do what you want in Portrait Upside Down
viewController1=[[SplashLandscapeViewController alloc] initWithNibName:#"SplashViewController" bundle:nil];
}
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
And this is working fine. And this viewcontroller1 is dissmiss after 4,5 seconds and load another viewcontroller. My problem is while that viewcontroller1 showing on the screen, if user turn the ipad how can I recogniz it and load my landscape .xib after removing the current portrait xib.
Please help me.
Thank you
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(changeOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
add this method into the app view controller for getting notification.
-(void)changeOrientation {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
[[NSBundle mainBundle] loadNibNamed:#"Portrait" owner:self options:nil];
}
else {
[[NSBundle mainBundle] loadNibNamed:#"Landscape" owner:self options:nil];
}
}
I'm making an ios app, I want to make all pages are landspace.
The first page is landspace, but the second page is portrait (going the second page via button).
How to make it landspace.
(I'm not using storyboard)
Button click event:
PanelController *panel = [[PanelController alloc] init];
[self.navigationController pushViewController:panel animated:true];
How about this ?
-(void)viewWillAppear:(BOOL)animated
{
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *controller = [[UIViewController alloc]init];
[controller.view setBackgroundColor:[UIColor whiteColor]];
[self.navigationController presentViewController:controller animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}];
}
The correct technique for changing orientation should be this:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
i have this code i want to go to another uiview but i want to have showing this view (second view) in portrait mode only and the notification in first view doesn't work in second view ;
is there any way to change the for this
[[NSNotificationCenter defaultCenter] removeObserver:self];
view2 *viewController = [[[view2 alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:navController animated:NO];
i want exactly one function same this code in ios >6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
Try subclassing the UINavigationController and override the following methods :
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I've been trying several approaches to get the rotation working as expected but so far I've been facing some problems.
Now I would like to have one class with one xib file containing the 2 orientation views. One for portrait, one for landscape.
I am trying this in my main ViewController (the root controller set in the app delegate. But somehow it's failing : when I rotate, the view is switched but the outlets are not rotated. For instance a simple label from the landscape view will be shown as if the device was in portrait mode.
Here's bits of code :
In my app delegate
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
//self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil withOrientation:UIInterfaceOrientationPortrait];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
In Viewcontroller.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:#selector(updateLandscapeView2) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView2
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
self.view = self.landscapeView;
[[NSNotificationCenter defaultCenter] postNotificationName:#"landscape" object:nil];
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
self.view = self.portraitView;
[[NSNotificationCenter defaultCenter] postNotificationName:#"portrait" object:nil];
}
}
I intend to forward the orientation change to the subviews of Viewcontroller by using local notifications.
Anyway, what am I missing here ? I don't understand why this is failing.
What i have found is that when you call
[UIDevice currentDevice].orientation
inside the context of a
[viewController performSelector .....]
It didn't work.
Some body with a solution for these?