If I’m not setting Splash image programatically every thing fine, But I’m setting it because black screen appears if my web service taking long time. So i decided to set an image to window like this.
UIImage *splashimg;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 480)
splashimg=[UIImage imageNamed:#"Default.png"];
else if (screenBounds.size.height == 960)
splashimg=[UIImage imageNamed:#"Default#2x.png"];
else if (screenBounds.size.height == 1136)
splashimg=[UIImage imageNamed:#"Default-568h#2x.png"];
else if (screenBounds.size.height == 1334)
splashimg=[UIImage imageNamed:#"Default-667h#2x.png"];
else if (screenBounds.size.height == 2008)
splashimg=[UIImage imageNamed:#"Default-Portrait-736h#3x.png"];
else
splashimg=[UIImage imageNamed:#"Default568.png"];
}
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
if(UIDeviceOrientationPortrait)
{
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)] && [[UIScreen mainScreen] scale] == 2){
splashimg=[UIImage imageNamed:#"Default-Portrait#2x~ipad.png"];
}
else if([UIScreen mainScreen].bounds.size.height==1536 )
splashimg=[UIImage imageNamed:#"Default1024x768#2x.png"];
else if([UIScreen mainScreen].bounds.size.height==1024 )
splashimg=[UIImage imageNamed:#"Default768x1024.png"];
else {
// splashimg=[UIImage imageNamed:#"Default768x1024.png"];
splashimg=[UIImage imageNamed:#"Default-Portrait~ipad.png"];
}
}
else
{
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)] && [[UIScreen mainScreen] scale] == 2){
splashimg=[UIImage imageNamed:#"Default-Landscape#2x~ipad.png"];
}
else
{
splashimg=[UIImage imageNamed:#"Default-Landscape~ipad.png"];
}
}
}
splashView=[[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
float width = ((UIScreen *)[UIScreen mainScreen]).bounds.size.width;
float height = (((UIScreen *)[UIScreen mainScreen]).bounds.size.height);
splashView.frame=CGRectMake(0,0, width, height);
splashView.image=splashimg;
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
[self performSelector:#selector(LoadViewnearby) withObject:self afterDelay:0.1];
// here is a web service Which is taking long time, So my window appears white,so instead of white i want to show the image which is same as splash.
I want to do exactly like splash. But my image view is getting compressed horizontally when compared to original splash.
Please help me…
Thank you..
Related
Ok tried almost everything and it didn't work.
I need my engine to start up in LandscapeRight mode, therefore i call:
//
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
The problem is that the rest is not rotated at all,
I managed to rotate the view by using:
[pExternViewController setTransform:CGAffineTransformMakeRotation(M_PI/2.0f)];
But it doesn't work as expected, the Frame Buffer size is correct now:
FrameBuffer: width: 960, height: 640
Still you can see it is not 960x640, and i can't figure out why?
Ok, finally made it.
First add this key to your plist file (required)
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
Screen Size definitions
#define SCREEN_WIDTH (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height) : [[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width) : [[UIScreen mainScreen] bounds].size.height)
#define IOS_VERSION_LOWER_THAN_8 (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1)
The window initialization
- (void) applicationDidFinishLaunching: (UIApplication*) application
{
// Start in Landscape
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
// Disable Auto Lock screen
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
// Set Bounds with the proper screen resolution
CGRect screenBounds = [[UIScreen mainScreen] bounds];
screenBounds = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
// Create window and view controler
m_window = [[UIWindow alloc] initWithFrame: screenBounds];
m_window.backgroundColor = [UIColor redColor];
// Create new view controller
pExternViewController = [SvgzViewController alloc] ;
// Initialize view controler with all pointers set up
if( [pExternViewController initWithFrame: screenBounds ] == nil)
{
assert(!"Failed to initialize screen");
exit(0);
}
// Rotate the window
[m_window setTransform:CGAffineTransformMakeRotation(M_PI/2.0f)];
// Set the proper window center after transformation
m_window.center = CGPointMake(screenBounds.size.height/2, screenBounds.size.width/2);
// Add GL window
[m_window addSubview: pExternViewController];
//
[m_window makeKeyAndVisible];
}
At least no GL side change has to be done by doing it this way.
I have a universial app .I added Launch images to project .
I want to wait splash screen until download json from webservice. my app it's waiting until download json. but launch image choosing is not correct or position.I wrote this following code.for example: my launch image correct on iphone 5 . but not on iphone 3gs.
How can I do that easily? sorry my English . Thank you.
CGRect screenRect = [[UIScreen mainScreen] bounds];
float screenWidth = screenRect.size.width;
float screenHeight = screenRect.size.height;
splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
NSLog(#"height %f version %f",[[UIScreen mainScreen] bounds].size.height,sysVer);
if (sysVer <7.0)
{
// iOS-6.01 and prior code
if (screenHeight==480)
{
splashView.image=[UIImage imageNamed:#"Default"];//iPhone
}
else if (screenHeight == 568.0f)
{
splashView.image=[UIImage imageNamed:#"Default-568h#2x.png"];
}
}
else // for ios7
{
if (!screenHeight == 568.0f)
{
splashView.image=[UIImage imageNamed:#"Default"];//iPhone
}
else
{
splashView.image=[UIImage imageNamed:#"Default-568h#2x.png"];
}
}
}
else
{
if (sysVer <=6.1)
{
splashView.image=[UIImage imageNamed:#"Default-Portrait"];// iPads
}
else
{
splashView.image=[UIImage imageNamed:#"Default-7681024"];// iPads
}
}
[self.view addSubview:splashView];
log is on iphone 3gs
height 480.000000 version 6.100000
This question already has answers here:
How to detect iPhone 5 (widescreen devices)?
(24 answers)
Closed 9 years ago.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
//NSLog(#"phonesize%#",result);
if(result.height > 500){
NSLog(#"iPhone 5");
}
else{
NSLog(#"iPhone 4");
}
}
My Mac OS is 10.7.2 and Xcode 4.5.2.I used above code to find device is iPhone 4 or iPhone 5
It is giving iPhone4 when i uses iPhone5.I did set launch image and icon image. Is there anything else i missed out?
Make sure you have a PNG file named Default-568h#2x.png in your project.
You need to scale the result you got as per the screen's scale scale and then check ...
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: #selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960) {
NSLog(#"iPhone 4");
}
if(result.height == 1136) {
NSLog(#"iPhone 5");
}
}
else{
NSLog(#"Standard Resolution");
}
}
Try this code instead its tested.
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
{
//device is iPhone
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
//device is iphone 5
//add storyboard/Xib that have large screen (320*568)
} else {
//device is iphone 4
//add story board/Xib that have small screen (320*480)
}
}
else
{
//device is iPad
}
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
//iphone 5
else
{
//iphone 4
}
}
else
{
//iPad
}
Try this one might be helpful to you...
I want to increase the size of a custom button if the user is using an iPhone 5.
This is what I have in my .m file
//.m File
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
int varWidth = 228;
}
if(result.height == 568)
{
int varWidth = 272;
}
}
....
[newButton setFrame:CGRectMake(8.0, 40.0, 228, 80.0)];
But I want something like this:
[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
You are using varWidth out of it's scope.
int varWidth;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
varWidth = 228;
}
if(result.height == 568)
{
varWidth = 272;
}
}
....
[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[newButton setFrame:CGRectMake(8.0, 40.0, 228.0, 80.0)];
}
if(result.height == 568)
{
[newButton setFrame:CGRectMake(8.0, 40.0, 272, 80.0)];
}
}
Why not do this way?
Another suggestion:
Use #define.
For example:
#define iPhone5width 272
#define iPhone4width 228
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[newButton setFrame:CGRectMake(8.0, 40.0, iPhone4width, 80.0)];
}
if(result.height == 568)
{
[newButton setFrame:CGRectMake(8.0, 40.0, iPhone5width, 80.0)];
}
}
The Best and Short way, For check device is iPhone 5 or iPhone5 < (Less Then).
For get this you need to write following code in your .pch file of project.
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
This Like check device, is it iPhone5 or not.
And you need to write only one condition for manage it
if( IS_IPHONE_5 )
// set or put code related to iPhone 5.
else
// set or put code related to less then iPhone 5.
I've a UIView under a table.
I've got to set UIView height for iPhone 4S or 5.
I tried using
- (void) regolaViewPeriPhone {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
CGRect frame = CGRectMake(0, 210, 320, 245);
_pickerContainerView.frame = frame;
}
if(result.height == 568)
{
CGRect frame = CGRectMake(0, 210, 320, 290);
_pickerContainerView.frame = frame;
}
}
}
but it doesn't work, what's right method? Thank you!
[ [ UIScreen mainScreen ] applicationFrame ]
This is the way to "Set UIView height depending on screen size"
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
//Do u r stuff here for Iphone 5
}
else if(screenBounds.size.height==480)
{
//Do u r stuff here for Iphone 4s
}
//if my answer is correct then vote up for me...