ipad landscape/ portrait image - ios

I am working on UI issue of ipad app development (about image). I have read some documents on apple development site but i cannot find any information about it.
Is there any file convention for image files to distinguish which image the system should load for Landscape/Portrait. Because I see that for launching image, we can use "MyLaunchImage-Portrait.png" & "MyLaunchImage-Lanscape.png". I have tried to add "-Landscape", "-Portrait", "-Landscape~ipad", "-Portrait~ipad" to other images for general use but it fails.
Is there anyone who has encountered this issue before?

Unfortunately there is not standard convention for this other than the iPad's launch images. However, you can use NSNotificationCenter to listen for orientation change events and respond to them accordingly. Here's an example:
- (void)awakeFromNib
{
//isShowingLandscapeView should be a BOOL declared in your header (.h)
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
[myImageView setImage:[UIImage imageNamed:#"myLandscapeImage"]];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
[myImageView setImage:[UIImage imageNamed:#"myPortraitImage"]];
isShowingLandscapeView = NO;
}
}

Related

XCDYouTubeVideoPlayerViewController: Exit fullscreen when rotate to UIDeviceOrientationPortrait

I use XCDYouTubeKit library for my iOS project. I present video from nonFullScreen mode with code:
self.videoPlayer = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:self.youtubeID];
[self.videoPlayer presentInView:self.videoView];
[self.videoPlayer.moviePlayer play];
When iPhone rotate to landscape mode i set FullScreen video with catching rotate current ViewController:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if (fromInterfaceOrientation == UIDeviceOrientationPortrait) {
[self.videoPlayer.moviePlayer setFullscreen:YES animated:NO];
}
But how i can catch rotation XCDYouTubeVideoPlayerViewController in fullScreen video mode??
Thank
My decision
in this class i add in viewDidLoad observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
And execution
- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification; {
if ([self.videoPlayer.moviePlayer isFullscreen] && [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
[self.videoPlayer.moviePlayer setFullscreen:NO animated:YES];
}
}
I think the easiest way to get this information is to subclass XCDYouTubeVideoPlayerViewController and override didRotateFromInterfaceOrientation: and/or viewWillTransitionToSize:withTransitionCoordinator:

segue enable Rotation

Can any one help, the code below works from the portrait view when the app starts, if i rotate to landscape if works great and shows the new view, but when rotate back to portrait, instead of getting the original view, I just get a crash, many thanks
`
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self enableRotation];
}
- (void)didRotate
{
[self setNeedsStatusBarAppearanceUpdate];
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft ||
[UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
[self performSegueWithIdentifier: #"segueToNumbers"sender: self];
}
else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait ||
[UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown){
[self performSegueWithIdentifier: #"segueToChoose"sender: self];
}
}
- (void)enableRotation
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
`
Do not respond to rotation events. You need to design you UI with AutoLayout to adjust to different screen size. in iOS 8 the orientation is irrelevant, your code should consider size classes instead

Alternative to private -[UIDevice setOrientation:] for forcing camera overlay into portrait mode

I am making a camera app for iPad. I want the camera app to work only in portrait mode. I had to put in a rotation observation, and force the device to use portrait mode like this:
UIImagePickerController in Landscape
I think this is private API; some of the users on the post suggested that it is.
If so, what other work around can I use to force the overlay to stay in portrait mode only? If I don't add this code it rotates to both portrait and landscape mode.
//Is this private?
#interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
#end
-(IBAction)InitiateCamera
{
overlayview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
...
...
//monitor device rotation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
//launch camera
[self presentViewController:picpicker animated:YES completion:nil];
}
- (void) didRotate:(NSNotification *)notification
{
//IS THIS PRIVATE?
//Maintain the camera in portrait orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Use this code instead. I submitted an app and it got approved on itunes
- (void) didRotate:(NSNotification *)notification
{
[[UIDevice currentDevice] performSelector:NSSelectorFromString(#"setOrientation:") withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
}
Yes it is. Though the orientation property appears in the UIDevice header, it's marked as readonly in that header.

How do I hide a UICollectionView?

I'm writing a program that detects a change in orientation of the device (portrait to landscape, etc.). When the device is in portrait a collectionview should be displayed and a scrollview should be hidden. When the device is in landscape mode the collectionview should be hidden and the scrollview should be displayed.
Through NSLogs I have confirmed that rotating the device is detected. and the hidden property is being set to YES.
I has essentially the same code working with two scrollviews, but due to performance issues I switched to using a collectionview and now it doesn't work. Any advice would be much appreciated. Thank You!
I have this code in the viewDidAppear method:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(detectOrientation) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
And this code in the detectOrientation method
-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
[myCollectionView setHidden:YES];
myPanoramicScrollView.hidden = NO;
NSLog(#"collectionView.hidden = %hhd", myCollectionView.hidden);
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
myPanoramicScrollView.hidden = YES;
[myCollectionView setHidden:NO];
NSLog(#"collectionView.hidden = %hhd", myCollectionView.hidden);
}
}

View Orientation changes

Update: I found why it was loading the same view the whole time. I now fixed that. It was a typo
ControllerForSplitViews.m
- (id)init
{
self = [super initWithNibName:#"ControllerForSplitViews" bundle:nil];
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
self.view = landscapeView;
}
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
self.view = portraintView;
}
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
return self;
}
This works.
Now the problem. When the view is loaded and running I change the orientation and load a different view from the same nib file, Fixed: but as soon as I do this the other UI elements disappears and only the ui elements of my landscape view is kept and when I rotate the device again it doesn't load my portrait view again? Any suggestions why this might happen?
-(void) orientationChanged:(id)object
{
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
self.view = portraintView;
}
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.view = landscapeView;
}
}
New Problem, each time I change the orientation it loads the opposite orientation's view
Thanks
I am adding this here as well for incase someone ever reads this, they might want to check out this post here where a simular scenario was discussed
Two views Multiple UIPickerViews Single outlet
Ok so I found a fix that works, but I have no idea why my original code didn't work what I did was:
Remove:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
Remove:
-(void) orientationChanged:(id)object
{
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
self.view = portraintView;
}
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.view = landscapeView;
}
}
Change:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscapeView;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portraintView;
}
return YES;
}
And now it works perfectly

Resources