UIview layout not autosizing for iPhone retina 4 inch screen - iphone

Xcode 5 storyboard app.
When I tap on button in the app, choosing a property - UIView opens, but only shows the correct layout for the first View.
When swiping left/right - the layout of all views is fine. The problem only happens when I tap on any button, except the first one. All the settings for all views and all code in .h and .m files are equal.
I use iCarousel for swipes.
Screenshots will help you to understand the problem better:
Right:
![Correct layout]
http://i.stack.imgur.com/b0HEP.jpg
Wrong: (see blank space at the top and bottom)
![Incorrect one - has to look like Pic.1]
http://i.stack.imgur.com/xqTmH.png
I don't want to mess with auto layout because scrollviews doesn't work properly with it. Any help would be appreciated! Thanks!

Check out if this works. I too had a issue of same kind where the position of top and bottom margin has shifted. I used this in viewDidLoad method.
if( [self respondsToSelector:#selector(setEdgesForExtendedLayout:)] )
{
self.edgesForExtendedLayout=UIRectEdgeNone;
}
or else set frame for iPhone retina 4 inch screen like this
if(IS_IPHONE_5)
{
tableView.frame = CGRectMake(0, 0, 320, 560); // something like this in DidLoad method or in viewWillAppear method
}

Related

Can't have a UIViewPicker well laid for iphone 4 & 5

I have one storyboard file for iPhone devices, and in one of the views there is a subview that contains a UIPickerView, and, when it runs on the iPhone 4 the UIPickerView is stuck at the bottom of the view as it should be, but when it comes to the iPhone 5, the UIPickerView appears a little above of the bottom of the screen.
If I fix the problem for the iPhone 5, the UIVPickerView won't appear completely when I run it on the iPhone 4. (half of it appears below the screen)
So is there a way to have the UIViewPicker well laid for both iphone 4 and 5 resolutions?
NOTE: I solved the issue by creating a completely new subview with the UIPickerView. Now it is well laid whatever the device is.
When creating the picker, you need to use the size of the screen to determine the location. It seems like you are just putting in the coordinates for the y manually, which only works when using one screen size.
If your view that you are in is the same size as the screen, as it most likely is but may not be, you can do:
int y = self.view.frame.size.height;
and use that as the y-coordinate of your pickerView.
Otherwise, you can find the size of the screen by using:
[[UIScreen mainScreen] applicationFrame].size.width //if in portrait
//or
[[UIScreen mainScreen] applicationFrame].size.height //if in landscape
Then you have to subtract the height of the navigationController from that if you have one.
If you're using autolayout, you should be able to change the constraints the picker uses to get it to stick to the bottom. Select the picker, click the "H"-shaped autolayout menu icon in the bottom right corner of the storyboard, and choose "Bottom Space to Superview". Then delete any constraints attaching the picker to the top of the screen. If that doesn't work, make sure that all of the picker's superviews have constraints to attach them to the bottom, too; you'll have to decide whether you want them to resize or slide down on an iPhone 5.
I fixed the issue. Not sure what was going wrong but I deleted the subview, then created a new one and added the UIPickerView. Surprisingly, now it is well laid whatever the device is.

How to make a UIView Scrollable?

Hi there I have a UIView with a bunch of UITextfields. My problem is that my UITextfields are present from the top to the bottom of my screen. So when the keyboard pops up, it covers half the screen and consequently the UITextfields below...What can I do so that all the fields can be edited by simmply scrolling when the keyboard is visible?
You need to embed your UIView into a UIScrollView and then change the size of the UIScrollView when the keyboard pops up.
Just give the view a new transform that moves it up. Eg.
[myView setTransform:CGAffineTransformMakeTranslation(0, -keyboardSize.height)];
Thats also animatable, just give it the same animation values as the keyboards and it will look perfect.
This solution is from XCode 5, iOS 7.0 and Storyboards. It worked for me quite well.
http://www.youtube.com/watch?v=4oCWxHLBQ-A

UIWebView won't fill screen

Edit: This was a result of my own stupidity - the website I was liking to (iphone optimised) was not resizing to take advantage of the extra space, other pages display full screen.
Hi,
I've been trying to create a view that has no navigation bar, just a UIWebView that takes up the entire screen with a button to exit the view. I've managed to find a solution to hiding the navigation bar, but the problem is, it leaves a 44px space at the bottom of the view. So what I have is a webview taking up 460px on the screen, then just a white area below.
In Interface builder I tried to edit the size of the view but it was greyed out and set to 460px. Is there a way to make it so the webview takes up all 480px?
Thanks for any suggestions.
Chris
You can set the size of UIVewView programmatically in this way:
myWebView.frame = CGRectMake(0, 0, 320, 480);
and place it by example in viewDidLoad method.

Strange black bars in UITableView

I'm really scratching my head over this one: When I make visible the Toolbar of the navcontroller in my view hierarchy, strange black bars appear at the top and bottom of the table view. http://grab.by/8pgz
The app is universal, and on the iPhone simulator (or device) this does not show up, although they use the same UITableViewController subclass.
I cannot even figure out what the extra bars are, which makes it even harder to come up with a solution.
They are, however, not navbar / toolbar. They are not section or table view header / footer. It does not merely seem to be a resizing of the table view either, since its background is not black.
The custom table view controller sits inside a UINavigationController, which in turn is inside a UISplitViewController. Pretty standard, as far as I understand.
Like said, they do not show up on the phone - nor do they appear in the popover in portrait orientation.
I'm really out of clues here. Any suggestions would be most welcome.
Cheers,
Gregor
Sweden
Update: Problem solved by moving the code for making toolbar visible to -(void)awakeFromNib method instead of -(void)viewDidLoad. Still don't know what went wrong, but now at least it works.
I believe there is a problem with the frame you're trying to use to initialize the tableView.
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, height, width);
Try changing the height width variables in code, to reflect your height & width on the iPad.

Set the height of a UITextView from a UIViewController's viewWillAppear event

I'm trying to set the height of a UITextView from a UIViewController's viewWillAppear event, here's the code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
textView.text = blah blah...
textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y,
textView.frame.size.width, textView.frame.size.height-20);
}
However, it seems to ignore my sizing, it's as though after this event is called, the textview is resized by something else.
What am i doing wrong? Is there some good way to do this?
Thanks
-edit-
Got it working by putting the code in my viewDidAppear instead of the viewWillAppear.
So it works now.
Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill automatically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top. Is that confusing it?
Simple but obvious question, does the text change, in other words, is the outlet hooked up in IB?
JUSTA TIP: Look at using the helper functions for CGRect such as:
textView.frame = CGRectInset(textView.frame, 0, 20);
In an app with just this code and a single TextView the resizing occurs as expected. So..it's definitely something else in your app.
Are you maybe referencing the contentsize property or something else in your viewDidAppear?
Got it working by putting the code in my viewDidAppear instead of the viewWillAppear.
So it works now.
Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill automatically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top.