I am working on a application which has to play videos when clicking on some thumbnail, I am displaying list. I want only the Video to rotate in Landscape and Portrait Mode but other screens must in Portrait Mode How can we do this.
In ViewWillAppear
UIViewController *vc = [[UIViewController alloc] init];
[self presentViewController:vc animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
This will trigger the redrawing of the view and thus calling following functions, provided you have implemented these
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Related
I have implemented this code in AppDelegate.m
-(UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow :(UIWindow *)window
{
UIViewController *currentVC = [(UINavigationController *)[UIApplication sharedApplication].delegate.window.rootViewController topViewController];
if ([currentVC isKindOfClass:[VideoPlayerVC class]])
{
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
and pushing to the VideoPlayerVC with link like this :
NSURL *link = [NSURL URLWithString:strUrl];
VideoPlayerVC *vc = [[VideoPlayerVC alloc] init];
vc.videoUrl = link;
[self.navigationController pushViewController:vc animated:false];
This allows me to enable autorotate in the VideoPlayer ViewController but when the video playback ends in Landscape mode, the entire app is being converted into Landscape view mode only.
Please help me guys to fix the issue.
Thanks in advance.
The system only tries to invalidate your orientation when a full screen modal presentation happened or dismissed. So I suggest you to replace your [self.navigationController pushViewController:vc animated:false]; with [self presentViewController:vc animated:YES completion:nil];
And if your UE needs the navigation transition, you can try to mimic it with UIViewControllerContextTransitioning customization.
Also there is a tricky method if you must use push behavior(It's the only one method not using private api as I know)
Every time you push/pop from the navigation stack, call the code below:
[[vc presentViewController:[UIViewController new] animated:NO completion:^(BOOL completed){
[vc dismissViewControllerAnimated:NO completion:nil];
}];
The code try to make an invisible vc and dismiss it immediately to make iOS update the supported orientation.
I present my second VC like this.
UINavigationController *nav = [[UINavigationController alloc] init];
[nav setViewControllers:#[vc] animated:NO];
[self presentViewController:nav animated:YES completion:nil];
In that second VC, I write this and that method is also being called.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
However, when I rotate my phone, it change to landscape. May I know how to stop that? In my other views, I need to support for landscape but not for this view. How shall I do?
I have an app in which only portrait mode is allowed. I am using a subclassed qlPreviewController for showing preview of an image. All orientations are allowed in this. But when I dismiss the preview controller in landscape mode , my UIView Controller's ui collapses. I i use following code in UIViewController's viewWillAppear method, My ui becomes correct.
if i use
-(void)viewWillAppear
{
UIViewController *c = [[UIViewController alloc]init];
[c.view setBackgroundColor:[UIColor clearColor]];
[self.navigationController presentViewController:c animated:NO completion:nil];
[self performSelector:#selector(delay) withObject:self afterDelay:1.0 ];
}
-(void)delay
{
[self.navigationController dismissViewControllerAnimated:NO completion:nil];
}
Can any one suggest the reason for this and a better method to do it
In order to restrict the app to only use portrait mode, I created a BaseViewController class as subclass of UIViewController and allowed only portrait mode in it. I created all other view controllers in the app as a subclass of this BaseViewController. Code in the BaseViewController is :-
-(BOOL)shouldAutorotate
{
return FALSE;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
is it possible to use UIImagePickerController to fetch image from gallery without making whole app in portrait mode in iOS .Thanks
Create a custom class of UIImagePickerController. Override supportedInterfaceOrientations meted
- (NSUInteger) supportedInterfaceOrientations
{
//Because your app is only landscape, your view controller for the view in your
// popover needs to support only landscape
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate{
return yes;
}
//call custom view like this
CustomImagePickerViewController *picker = [[CustomImagePickerViewController alloc] init];
picker.supportedInterfaceOrientations= UIInterfaceOrientationMaskAll;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
I'm creating an app that is landscape only, it uses an image picker control.
Looking through the site I've discovered that apple only allow portrait for this for some reason. I'm okay with it flipping to portrait for this one section, if it means the user can select a photo from the library.
Below is my code that gives an error about it being in landscape mode. How do I fix this to say it's okay to flip it to portrait. thanks
-(IBAction)takePhoto{
takePicker = [[UIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[UIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}
You don't have to use ImagePickerController in portrait mode.
Just subclass it to open in landscape mode :
#interface NonRotatingUIImagePickerController : UIImagePickerController
#end
#implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return NO;
}
#end
After that, you can use your code with that class.
-(IBAction)takePhoto {
takePicker = [[NonRotatingUIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[NonRotatingUIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}
Why present an error at all? Why not just present the image picker in portrait? People are smart enough to rotate their device. Or you could write your own landscape image picker, or use one of the several open source ones available.