UIPickerView animated on bottom for both retina 3.5 and 4 - ios

Have an UIScrollView (mainScrollView) that is 838 pt height, so it's bigger than both retina 3.5 and retina 4 displays height, and the user can so scroll it down to see all content.
Want to display an animated UIPickerView from the bottom, and it should stay always on the bottom of the screen, independent of screen height (retina 3.5 or 4) or mainScrollView (838 pt) height.
Is there a way to get the "window" or "screen" height and add UIPickerView considering the measures for the different screens? What should be the correct approach to accomplish this?

This will return the frame of screen
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
With this you can position your picker accordingly !!!

Related

iOS scroll view bounds not equal to superview bounds

I've got a UIScrollView that has constraints pinning it to the superview's leading and trailing edges (not the margins). In this scroll view I have a UIImage which I'm setting to initially be the full width of the scroll view. On the iPhone 7 this works correctly, the image is full width
However on the iPhone 7 Plus there is a gap between the edge of the image and the edge of the screen. The scroll view is full width as when I zoom the image in it does go right to the edge.
I'm getting the image to match the scroll view width by setting
imageView.frame = scrollView.bounds
imageView.contentMode = .scaleAspectFill
The issue seems to be the scroll view bounds. On the iPhone 7 Plus the scroll view width is reported as 375, however the screen width is reported as 414. On the iPhone 7 the scroll view width is 375 and the screen width is also 375.
Anyone know why this is? I'm sure I'm misunderstanding something!
Most probably your problem is that scrollView's frame is not updated yet when you use it to set imageView's frame.
Try to move layout code into viewDidLayoutSubviews instead:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
imageView.frame = scrollView.bounds
}

Bottom UIToolbar off screen on iPhone 4 and 4S

My problem is very similar to UIToolbar not displaying on iPhone 4 and iPhone 4s
I am using Xcode 7 and am trying to get a 'legacy' UINavigationController based iPhone app up and running on various iPhone screen sizes. By legacy , I mean it does not use Storyboards etc. The views are loaded from an .xib.
The app is a classic UINavigationController app with UITableViewControllers but with a UIToolBar at the bottom underneath the table view. The TableView and ToolBar are subviews of the view of the ViewController.
Works great on iPhone5/5s/6/6s.
But on the iPhone 4/4s the toolbar is off the screen. Oddly if I rotate the screen to landscape, the toolbar appears. Rotate back, it vanishes. I know this seems like prehistoric iOS code, but I am completely at a loss here and have wasted hours fiddling in Xcode and IB. I know I am missing something obvious.
It seems like the height of your table view is set to be a fixed height where the toolbar is visible beneath the table view on iPhone 5 and up. To get the toolbar to display on iPhone 4/4s requires reducing the height of the table view's frame using something like the following code.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (onIphone4 && portraitOrientation) {
CGFloat height = 480 - self.toolbar.frame.size.height;
self.tableView.frame = CGRectMake(0, 0, 320, height); // for iPhone 4/4s
} else if (onIphone5 && portraitOrientation) {
CGFloat height = 568 - self.toolbar.frame.size.height;
self.tableView.frame = CGRectMake(0, 0, 320, height); // for iPhone 5 and up
}
}
You will probably need to change the y position in the frame origin to account for the status bar and navigation bar if they are also present. In that case, the overall frame height will need to be adjusted for those changes. This is the frame-based way of adjusting view sizes.
The alternative and preferred method is to add auto layout constraints in the XIB for the toolbar and the table view in Interface Builder so that they will maintain the proper size and position relative to the screen dimensions.
I found the issue.. it was the "Full Screen at Launch" checkbox in IB, for the main "UIWindow"... and I quote from Apple documentation....
"If you choose to create a window in Interface Builder, be sure to select the Full Screen at Launch option in the Attributes inspector so that the window is sized appropriately for the current device."
Now please excuse me while I slam head against wall..way to waste a Sunday!

Not getting a correct height for bounds of iphone screen

I am having trouble setting up the frame for one of my views. I know that the height in points of the iPhone 5 is 568, but when I enter this code into the viewDidLoad in my ViewController:
var height = self.bounds.height
println(height)
output:
640.0
Why does it come out as this when it should be 568? Is it a problem with the simulator?
I thin your viewController height is more than 568.You have did FreeForm.Check the height in Size inspector of your view controller.
Make simulated size fixed.
EDIT: You can make it portrait and iPhone 4 inch to show it correctly see below.
To get the height of the screen you want the height of the VIEW. To do that you would want:
DO NOT PUT:
var height = self.view.bounds.height
DO:
var height = self.view.bounds.size.height

Contents clipped using autolayout in 3.5 inch screen

i am using autolayout in my project. I added the contraints from the bottom to the top. Everything works fins in 4 inch screen . But screen is clipped when the project is run on 3.5 simulator.
Looking at the screenshots, it looks like there is no space to fit all your elements.
One way to go about it is, dock the elements at the top of the screen using the Top Space To Superview constraint, and dock the elements at the bottom using the Bottom Space To Superview constraint.
When you do this, if there's not enough space available, you'll probably see some of your subviews overlapping around the middle.
You can consider solving this by using a UIScrollView as a top level subview and add all your subviews to the scrollView. The content height of the scrollView will be calculated based on your constraints.
You can also manually set the contentView height after viewDidLayoutSubviews is called.
Personally I find that sometimes I can't seem to get Autolayout to work exactly as I want. So its worth putting a check in your viewDidLoad to manually move objects around a bit if the screen size is a 3.5 inch screen like so:
In my example I will be using a Button:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480) {
// 3.5 inch display
button.frame = CGRectOffset(button.frame, 0, 89.0f);
}
if (result.height >= 568) {
// 4 inch display
// .....
}
}

Available screen height with UINavigationBar + UITabBar

So I'm developing an app with a UINavigationBar on top, and a UITabBar on the bottom. And I'm having a hard time trying to figure out what is the real available height for the views.
I've tried calculating the available screen height by calculating the UINavigationBar height and UITabBar height and subtract it from the main screen height, but that is still not the real size.
Here's my failed code for obtaining the available screen height:
CGRect screenRect = [[UIScreen mainScreen] bounds];
_screenHeight = screenRect.size.height;
CGFloat tabBarHeight = _rootViewController.tabBar.frame.size.height;
UINavigationController* navigatior = _rootViewController.viewControllers[0];
CGFloat navigationBarHeight = navigatior.navigationBar.frame.size.height;
CGFloat visibleHeight = _screenHeight - navigationBarHeight - tabBarHeight;
return visibleHeight;
Is there a clean way to know the real available screen size in an UINavigationBar + UITabBar based app??
You don't need to calculate it and it changes depending on the iPhone. Your best bet and easiest path is to use the storyboard and embed both your navigation controller and tab bar directly in there. Once you have done that, you can use auto layout to pin your views to the bars and everything will be sized perfectly for you.

Resources