UIScreen bounds and applicationFrame difference between iOS6 and iOS7 - iphone

Using iPhone4s iOS7, Screen orientation is Landscape
-Build an application with below SDKs
I built the application with iOS6 SDK and iOS7 SDK, and checked each of the screen resolution. Below shows the result:
iOS6 SDK:
[[UIScreen mainScreen] bounds] == (0, 0, 320, 480)
[[UIScreen mainScreen] applicationFrame] == (0, 0, 300, 480)
iOS7 SDK:
[[UIScreen mainScreen] bounds] == (0, 0, 300, 480)
[[UIScreen mainScreen] applicationFrame] == (0, 0, 320, 480)
Why do we get inverted value in iOS7?

Yes. In iOS6 and below, status bar is not included in the view. But in iOS7 status bar is included in the main view. If you are using navigation controller then you can get iOS6 behaviour by setting Translucent and Opaque property of the navigation bar.
[self.navigationController.navigationBar setOpaque:YES];
[self.navigationController.navigationBar setTranslucent:NO];
Similarly tab bar are also Translucent by default in iOS7. You can set them opaque by setting these properties.
[self.tabBarController.tabBar setOpaque:YES];
[self.tabBarController.tabBar setTranslucent:NO];

Related

Imageview not display Proper For Iphone 5 Retina

I am developing one app in that app display 20 array Images to Image view Scroll horizontally.
give scroll view to that imageview like this
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
for (m = 0; m <=19; m++)
{
rnd = arc4random_uniform(arr.count);
NSString *imageName=[FrontsCards objectAtIndex:rnd];
fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=0;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[scrollView addSubview:ImgView];
}
this imageview not display images Properly for iphone 5 simulator. below black edge add.
how may i solve that issue.how to remove that black edge.how to fit that image to Iphone 5 simulator.
how may manage my ImageView to Iphone 4 or Iphone 5.
Iphone 5 size is 568 and Iphone 4 size is 480.
scrollView=[[UIScrollView alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
// For Iphone5
scrollView.frame = CGRectMake(0, 0, 320, 568)
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
//For Iphone 4 or others
scrollView.frame = CGCGRectMake(0, 0, 320, 480)
}
this will really helpful to you.
Iphone 5 screen size is 568 and you have had codded height to 480. So it is not working for iphone5.
DO following
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, [[UIScreen mainScreen] bounds].size.height)];
Depending on devise scroll view height will change.
Try This
scrollView=[[UIScrollView alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) scrollView.frame = CGRectMake(0, 0, 320, 568)
else if ([[UIScreen mainScreen] bounds].size.height == 480) scrollView.frame = CGRectMake(0, 0, 320, 480)
So, it will help you to fill scrollview in iPhone-5 screen too.
Hopefully, it'll work for you.
Thanks.
scrollView=[[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
use this to make the UIScrollView dynamic
Use macro to check whether it is iPhone 5 or not.
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"] | [[[UIDevice currentDevice] model] isEqualToString:#"iPhone Simulator"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)];
You need to create design for iPhone 4 and iPhone 5.
Create a class which make decision which iPhone is connected and
make function on it which accept CGRect and return required size of CGRect
you can get device size by
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height < 500)
{
currentDeviceHeight=460;
//You can use use iPhone 4 image
}
else
{
currentDeviceHeight=548;
// here you can use iPhone 5 image
}
}
else
{
// iPad
}

Issues with migrating my app to iphone5 resolution

I am trying to migrate my app for iphone 5. I have already seen the other questions in stackoverflow and still facing the some problems in correctly showing it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,500)];
[_backgroundimageView setImage:[UIImage imageNamed:#"image1-568h#2x.png"]];
} else {
// code for 3.5-inch screen
[_backgroundimageView setImage:[UIImage imageNamed:#"image1.png"]];
}
The size I have set for backgroundimageView is 320 x370 in the size inspector and the image size of image1-568h#2x.png has a size of 640x 1136 and of image1.png is 640x733.So, for 3.5 inch screen, it should show normally and for 4-inch screen, it should resize accordingly.
But the problem is that for 4-inch screen, it doesn't resize and ends up showing me the same as 3inch screen with some white border to cover the remaining area.
Need some guidance to solve it. Thanks.. Can point out the mistake i am doing...
Why you are again allocating backgroundimageView for iPhone 5 resolutions. Just use the same IBOutlet of backgroundimageView and modify the frame and image of it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView.frame = CGRectMake(0,0,320,460);
[_backgroundimageView setImage:[UIImage imageNamed:#"image1-568h#2x.png"]];
} else {
// code for 3.5-inch screen
_backgroundimageView.frame =CGRectMake(0,0,320,370);
[_backgroundimageView setImage:[UIImage imageNamed:#"image1.png"]];
}
Default image name must be "Default-568h#2x.png" (not image1-568h#2x.png) try renaming the default image name and check again, you will get right screen size.
Also you can check iphone5 by macros.
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
I think content mode of your imageview is center so try this for your imageview
[_backgroundimageView setContentMode:UIViewContentModeScaleAspectFill]

UIWebView frame to fill screen when loaded landscape and portrait

I am adding a UIWebView to my view, which works fine when I am in portrait. But when I load that same UIWebView in landscape it does not fill the screen. I suspect it comes from how I am setting the frame:
CGRect screen = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
webView.scalesPageToFit = YES;
Is there a better way to do this so it will load correctly in both landscape and portrait, and fill the screen when rotated?
How sure are you that the parent view is resizing to the full width? UIWebView subview will not go larger than it's parent...
I had same problem.. After i Logged the self.view.frame.size.width i was surprised to find out thats it was 320 instead of 480. The solution to this was :
- (void)viewWillAppear:(BOOL)animated {
[self.view setBounds:CGRectMake(0.f, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[(UIWebView*)myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];}
Seems that the correct size of self.frame is returned just before showing the view :)

Iphone: Get current view dimensions or screen dimensions

Hello i want to get the width and height of my main view. I want the correct value in landscape or portrait mode. I've tried the following:
NSLog(#"aaa %f", [UIScreen mainScreen].applicationFrame.size.width);
NSLog(#"zzz %f", self.view.frame.size.width);
These give 300 in landscape and 320 in portrait mode, yes it is larger in portrait mode. So.. my view takes up the whole screen (- status bar) so I expect 480 in landscape mode and 320 in portrait mode. What happened to the rest of the pixels. Do I have to hardcode these values? Thanks.
Do either of the following lines work for you?
[[UIScreen mainScreen] bounds].size.height
[[UIScreen mainScreen] bounds].size.width
I suppose you can subtract the height of the status bar? Maybe i'm not understanding your question
Try this :
UIWindow* window = [UIApplication sharedApplication].keyWindow;
NSLog(#"%f",window.frame.size.width);
Useful macros that will give you the correct size based on the device orientation:
#define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)
#define SCREEN_HEIGHT ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width)

UIButtons don't respond to touch after set frame on autorotate

Hello in my app i have some uiButtons added as subviews to a view like in the picture below.
alt text http://img99.imageshack.us/img99/5244/portraitc.png
when the user rotates the phone in landscape the views and buttons must change position to this:
alt text http://img193.imageshack.us/img193/5931/landscapeq.png
initially when the view is in portrait mode the buttons respond to touches. If i tilt the phone the buttons move, everything looks ok like in the second image and the buttons respond to touches. If i tilt the phone back to portrait mode, the buttons move back they look ok but they don't respond to touches. If i change back to landscape the buttons work...
my buttons are created like this:
nextNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25)];
[nextNewsP setImage:[UIImage newImageFromResource:#"next_arrow.png"] forState:UIControlStateNormal];
[nextNewsP addTarget:self action:#selector(nextNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[nextNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:nextNewsP];
[nextNewsP release];
previousNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25)];
[previousNewsP setImage:[UIImage newImageFromResource:#"previous_arrow.png"] forState:UIControlStateNormal];
[previousNewsP addTarget:self action:#selector(previousNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[previousNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:previousNewsP];
[previousNewsP release];
bottomTools is a view and is added also as a subview like this:
[self.view addSubview:bottomTools];
[bottomTools release];
and my shouldAutorotateToInterfaceOrientation function looks like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView beginAnimations:#"moveViews" context: nil];
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(#"set frames for portrait");
closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 30, 2, 23, 25);
newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.width - 10, 22);
internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 55, 5, 18, 18);
industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-40, [[UIScreen mainScreen] bounds].size.width, 40);
nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25);
previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25);
}
else
{
NSLog(#"set frames for landscape");
closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 30, 2, 23, 25);
newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.height - 10, 22);
internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 55, 5, 18, 18);
industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.width-40, [[UIScreen mainScreen] bounds].size.height, 40);
nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 40, 10, 25, 25);
previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 85, 10, 25, 25);
}
[UIView commitAnimations];
return YES;
}
did you ever had a similar problem?
thank you in advance,
Sorin
I am actually still struggling with the same problem (a year later ... need iOS 3.0 compatibility). The rotation part was easy. However, the views and buttons don't seem to process touch and move/drag events. I've verified that the window (UIWindow) is receiving the touch events and at the right locations.
It's as if the last 1/3 of the screen (i.e. 480-320) doesn't propagate events to receivers after a rotation to landscape from portrait.
The example in the link by slf doesn't help since the rotated view controller doesn't have responders.
I just figured it out after some view digging. So, I was rotating the viewController.view and doing a bunch of setNeedsLayout on subviews of viewController.view. However, what I needed to do was [self.navigationController.view setNeedsLayout]. That one call fixed everything for me. For whatever reason, the navigationController.view wasn't passing touch events to the part of the subviews that were previously hidden (as far as the frame/bound is concerned). That actually fixed a number of other issues as well.
I think your problem is in your frame adjustment. My gut tells me it has something to do with the logic being inside shouldAutorotateToInterfaceOrientation because that happens before the rotation is actually done. Try doing your math the way they do it in this article and see if that helps.
I've fixed the problem I was having .. I basically needed to do [self.navigationController.view setNeedsLayout].
The way I understand this (which maybe incorrect is that self.navigationController.view.frame was same as self.view.frame and both were equal to (x=0,y=0,width=320,height=480). I then rotated self.view by M_PI/2 and did a number of frame manipulation on select self.view.subviews to get everything to animate/position/scale correctly.
That worked out okay but the navigation controller was not willing to acknowledge touch events to parts of self.view there were to the right of 320. In essence, if this self.navigationController.view.clipsToBounds were true, it might not even have shown that part of self.view.
Anyway, setting setNeedsLayout on the navigation controller's view resolved the issue. I hope this helps someone else. I suspect that was also the problem SorinA was having with buttons not getting touch events.