ipad splash screen doesn't rotate - ios

I would like to be able to rotate my splash screen on my ipad to landscape right and left.
i have enabled landscape right and left orientation in my .plist file. i've added 4 files for the LandscapeRight and LandscapeLeft:
Default-LandscapeRight#2x~ipad.png
Default-LandscapeLeft#2x~ipad.png
Default-LandscapeRight~ipad.png
Default-LandscapeLeft~ipad.png
although this shouldn't matter, in my rootviewcontroller i've got:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
}
The splash screen loads, but it doesn't rotate.
what am i doing wrong?

As I Know Device does not recognise the Orientation in the duration of Splash Image.These SPlash images Default-LandscapeRight#2x~ipad.png
Default-LandscapeLeft#2x~ipad.png
Default-LandscapeRight~ipad.png recognise when app going to launch device then device takes Appropriate Splash Image.
Default-LandscapeLeft~ipad.png.
You can do the Alternate solution if you interested.and this is just my concept nothing more
1 create the UIIMageView for this Purpose and Add it as SUbview to Window.
2 Set iamge to that UIIMageView.
3 Set Sleep method for 3-4 seconds. like sleep(4).
4 As call goes to RootViewController manage the Orientation of Image.
like below method
this is the Method suppose you have defind In The AppDelegate class will manage the Image Orientation.
-(void)checkOrientationforSplash:(UIInterfaceOrientation)interfaceOrentaion
{
if (splashImageView.hidden==FALSE) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
if (interfaceOrentaion==UIInterfaceOrientationPortrait|| interfaceOrentaion==UIInterfaceOrientationPortraitUpsideDown) {
UIImage *image=[UIImage imageNamed:#"Default-Portrait.png"];
splashImageView.frame=CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[splashImageView setImage:image];
}
else {
UIImage *image=[UIImage imageNamed:#"Default-Landscape.png"];
splashImageView.frame=CGRectMake(0.0, 20.0, image.size.width, image.size.height);
[splashImageView setImage:image];
}
}
}
5 You can Manage That Image Form in the Mid of App Instaltion, RoortViewController.
6 Remove That Splash Image At Specific Point.
-(void)removeSplash
{
[splashImageView setHidden:YES];
}
I hope it'll help you.

Related

iPhone : changing background image when rotating device using size classes

I placed a background image that needs to fill the iPhone screen. It is fine in portait view but when I rotate the device the top is cropped which I don't want.
The best seems to be an image for the portrait view and one for the landscape view.
I tried to use the size classes, assigning 1 image for compact W and any H and 1 for any W and compact H. I can't make it work.
I am using Xcode 6.3 and swift 1.2.
I made another app using the instructions in the book iOS 8 essentials (Neil Smyth) chapter 24 but it does not work. I downloaded the file "universal_images", thinking I was doing something wrong but it does not work neither.
This is the answer to my question.
1 - I added my two background pictures (one landscape version and one portrait version) in Supporting files , in a group that I named "images" (not necessary but tidier).
2 - In Main.storyboard, I added a View (via object library on the right inside bottom) that appears inside the already present view in the view controller scene.
3 - Inside that view I put an image view and in the editor -> image view ->image selected the portrait image file. View-> mode-> Aspect to fill
4 - I add constraints to the container view and image view through the pin menu 0 bottom, top, left , right.
5 - In ViewController.swift inside the class ViewController: UIViewController {…… I added the following code:
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
if (toInterfaceOrientation.isLandscape) {
println("Landscape");
background.image = UIImage (named: "BeethovenH.png")
}
else {
println("Portrait");
background.image = UIImage (named: "BeethovenV.png")
}
}
It worked perfectly.
Thanks for your help.
I always use two images: one for portrait and one for landscape and have different resolutions for different targets. This is the best way to guarantee your background looks right on different devices with different aspect ratios.
I always make the background a UIImageView contained in a separate UIView. Add constraints to all sides to pin the container view and image view to the edges. This ensures the image fills the screen for portrait and landscape automatically.
I have the following method to set the background for a given orientation. It relies on a factory class to load the appropriate image. Loading backgrounds requires more effort than normal images as size class does not tell you anything about the aspect ratio. Replace the MyImageFactory with whatever code you use to load the appropriate image.
- (void) setBackgroundImage:(UIInterfaceOrientation) orientation{
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(#"Setting background to landscape");
[self.backgroundImageView setImage:[MyImageFactory backgroundImageLandscape]];
}
else{
NSLog(#"Setting background to Portrait");
[self.backgroundImageView setImage:[MyImageFactory backgroundImage]];
}
}
Call the background setting method in viewWillAppear to initialise the background to the startup orientation as follows:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Set the background image
[self setBackgroundImage:self.interfaceOrientation];
}
Finally to deal with rotation, override the rotation method as follows:
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self setBackgroundImage:toInterfaceOrientation];
// Do anything else which is rotation specific.
}
Works well on iOS7 to iOS9.
I wanted to do this and it took me forever to find an ios 11/swift 4 version of the solution so I thought I would offer it here. You follow all the steps given in the answer above but the code is:
func changeBackground() {
//iPads etc
if traitCollection.horizontalSizeClass == .regular{
background.image = UIImage(named: "beethovenV.png")
}
else {
//compact width - most iPhones in portrait
background.image = UIImage(named: "beethovenV.png")
//iphone in landscape
if traitCollection.verticalSizeClass == .compact{
background.image = UIImage(named: "beethovenH.png")
}
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
changeBackground()
}
You need to do simple 2 steps
1.) Choose size class any,any it will run on both portrait and landscape mode for all devices both for ipad and iphone.
2.) Use autolayout and set constraint as shown in screenshot
It will work fine.Thanks

IOS XIB storyboard Launch Screen file displays wrong orientation of an image inside

I am using js based app with the support of ejecta kitchen. My problem is an image which i have set on the MainWindow that displays wrong orientation or in other words it displays fixed orientation. My application require everything to be displays in landscape mode but XIB file display things upside down whenever i change the orientation of my IPAD.
I have searched alot on internet but i could not find any possible solution yet.This is the only file which has this problem , other than this my index.html file works fine which is built on construct2.
Here is the image which displays the hierarchy of my window and image
As per your issue, you can write your code as below in AppDelegate method.
- (void) application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation
duration:(NSTimeInterval)duration
{
if (newStatusBarOrientation == UIInterfaceOrientationPortrait)
yourImage.transform = CGAffineTransformIdentity;
else if (newStatusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
yourImage.transform = CGAffineTransformMakeRotation(-M_PI);
else if (UIInterfaceOrientationIsLandscape(newStatusBarOrientation))
{
float rotate = ((newStatusBarOrientation == UIInterfaceOrientationLandscapeLeft) ? -1:1) * (M_PI / 2.0);
yourImage.transform = CGAffineTransformMakeRotation(rotate);
yourImage.transform = CGAffineTransformTranslate(yourImage.transform, 0, -yourImage.frame.origin.y);
}
}
as per the above code, you can rotate your Background image.

App support the app Landscape and portrait mode in both ipad and iphone

In my app i trying create a Interface builder supports both Landscape and portrait in ipad and iPhone.
[In Android we used fill parent to autoresize dynamically created UI-Elements.is there any syntax in iOS to autoresizing]
How to UI-elements create dynamically supports both Landscape mode and portrait mode?
How create the view controller to support the Landscape mode and portrait mode?
Is there required to create a all views and UI-elements dynamically?
1)If you will make xib or nib than develop xib or nib in only one mode as portrait or landscape. Than use Autoresizing option as below Image for any control.
http://www.raywenderlich.com/50319/beginning-auto-layout-tutorial-in-ios-7-part-2. You can use this link for auto layout.
But Auto layout is not work properly as you want. so u need to set frames of control pro grammatically evenif u r using autolayout.
2) And If you want to develop dynamically than using below code you can set frame of all controls.
In ViewwillAppear.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
in viewdidload
set your controls as below.
UILabel lbl - [UILabel alloc]init];
-(void)orientationChanged{
if(Orientation is portrait){
[lbl setFrame:for portrait];
}else{
[lbl setFrame: for landscape];
}
If device change mode than above notification fire and in that method. you can set frame of control.
I hope you will get your answer.
You can use auto - layout for providing both the portrait and landscape mode.
For more details, check this : What is Auto Layout?.
You have to set the constraints for landscape and portrait mode to work. Like if you want a button at the top, you can set constraints on it : from top and left and so on.
If you want a UI element to work change dynamically, you just need to change frame on orientation as per your requirement. Sample code is here :
# pragma mark - Orientation related methods
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(3_0)
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
[self deviceRotatedToLandscapeMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self deviceRotatedToLandscapeMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
[self deviceRotatedToPortraitMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self deviceRotatedToPortraitMode];
}
}
- (void) deviceRotatedToPortraitMode {
self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
}
- (void) deviceRotatedToLandscapeMode {
self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.height, self.view.frame.size.height);
}
The most reliable approach -
Create a method in your view controller -
-(void)setFrameForOrientationChange:(UIDeviceOrientation*) o {
//...
implement your code for frame settings..
}

iPad orientation is not only four in iOS

Now i realized when i writing my app for only iPad version.
My iPad iOS Version is iOS 5.1.
Yes, i need to check the iPad Orientation before load my Data.
So i check with following codes.
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
self.originalLandScape = CGRectMake(0, 48, 1024, 704);
self.originalPortrait = CGRectMake(0, 48, 768, 960);
self.txtView.frame = self.originalLandScape;
}
else
{
self.originalPortrait = CGRectMake(0, 48, 768, 960);
self.originalLandScape = CGRectMake(0, 48, 1024, 704);
self.txtView.frame = self.originalPortrait;
}
Because i need to set the fix size to my UITextView.
However i realized that when my iPad is with Landscape and put down to floor horizontally , It's not correct to set UITextView size.
But when i get my iPad from floor and holding in my hand with Landscape like reading book , my above codes is work.
Is there any different between those two?
I don't know how to solve it.
Thanks you for any suggestions and helps.
You are correct - iPad orientation is not only four, it is six:
UIDeviceOrientationLandscapeLeft
UIDeviceOrientationLandscapeRight
UIDeviceOrientationPortrait
UIDeviceOrientationPortraitUpsideDown
UIDeviceOrientationFaceUp
UIDeviceOrientationFaceDown
Your else clause therefore applies not just to the Portrait orientations, but to FaceUp and FaceDown as well.
I suspect that what you actually want to use is the Interface orientation. This may or may not be the same orientation as the Device orientation (depending on your app's supported orientations) - but if you want to draw a UI element correctly for a particular orientation, it will be the orientation of the rest of the interface that matters, not the device orientation.
There are only four interface orientations:
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
You can get these with the UIViewController property interfaceOrientation and check them with the UIKit functions UIInterfaceOrientationIsLandscape() and UIInterfaceOrientationIsPortrait()
Try this in your code
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))) {
...
} else {
...
}

Why is my ModalView displaying in portrait mode?

Hopefully somebody can point out what I'm doing wrong with my Splash screen here. The problem is that the screen is displaying in portrait mode, not landscape...
- (void)showSplash
{
UIView *modelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024 , 748)];
UIViewController *modalViewController = [[UIViewController alloc] init];
[modelView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Splash.png"]]];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:5.0];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Thanks in advance for the help.
Looks like you are writing app for iPad. If so, you have to support both landscape as well as portrait orientation otherwise Apple will reject it. I would suggest that you should use two different images. Image specifications are as follows:
Default-Landscape.png (1004 * 768)
Default-Portrait.png (748*1024)
(I am assuming that you are showing status bar if not add 20 pixels to height of an image)
That's it, create these images and add it to your project. And you are good to go. No Need to write any additional piece of code too..
And ya make it
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
You shouldn't rely on a function in your code to display the splash screen. Just define them as the previous answer from Sumit Lonkar explains.
If you do it in code, I believe at the start of the application the orientation is always considered as portrait, then the transition to the actual orientation is triggered. This explains why your code displays first as portrait and most likely there is nothing else in the code to handle rotation. Besides, the purpose of the splash screen is to display something while the app is loading, so if you put it in code you lose the purpose.
By doing it the Apple way you leave it to another Apple process that runs before looking at your code and it will work.
Regarding the orientation supported I have on my iPad some apps that support only landscape (TapZoo for example) so it should be ok with Apple.

Resources