I need to present a UI in a popover with arrow which has few controls that works on both iPhone and iPad. I am not sure what is the best way to do this that works correctly with Autolayout and resizing. Let's say I have a UIButton, UISlider, UIButton, UISlider in that order which are equally spaced vertically in the view, how do I set Autolayout constraints and present the view as popover that adapts to resizing? There are essentially two questions here -- how to display a view as popover with arrow and how to use autolayout to adapt to presentation size.
Related
I'm having a problem with moving subviews in different size classes, here is my problem.
I want to build two layouts for landscape and portrait (autolayout and size classes)
Here is the desired UI
In portrait I want the red view to be a subview of magenta view, while in landscape to move the red view to be the subview of the controllers view (the white view).
I can set different constraints for portrait and landscape for the red view, if it remains a subview to the magenta view and it all works fine.
But if I move it out to the white view, it disappears form the other orientation/size class.
Is there a way of solving this problem from Interface Builder, without duplicating the red view?
I'm trying to avoid to activate/deactivate constraints from code.
Link to the project.
Yes you can do that. From portrait size class set constraints. Then change size class for landscape and then drag this view out from it super view and put it to desired location.
And uninstall constraints of portrait class for this size class and set new required constraints for this size class.
Hope this will help :)
I have some UIButtons that when shows in portrait look like this
When I rotate the device to landscape, I want the label to be underneath the image.
I've seen this answer to getting the label beneath the button image - Label under image in UIButton but can't figure out how and where to implement this on device rotation that is safe.
My view hierarchy for this section looks like this with the UIScrollView as subview of the main UIView
I am targeting iOS 8 and using AutoLayout. I have seen some answers using layoutSubviews for other questions that do something similar but I've seen that layoutSubviews will be called on each rotation. I need this to only happen on landscape layouts.
Can anyone point to any guidance/documentation on how items should be placed in a view controller that will be displayed as a popover so that the components are appropriately positioned with auto layout?
Specifically: I'm working in Xcode 8.3 with the new "Present as Popover" segue, with the new "universal" storyboards. I add a view controller and then a popover segue to that view controller. When it is displayed, I see that roughly the top-left quadrant of the view controller is displayed as a popover, but that no auto layout appears to be taking place as far as I can see to accommodate the slightly different sizes of an iPad popover vs "full screen" behaviour on the different sized iPhones -- so in effect, a slightly different section of the view controller is visible depending on the device.
I assume this isn't really how things are supposed to work, and the whole raison d'ĂȘtre of the universal popover segue is to appropriately fit things to the popover size via auto layout? So can anyone shed some light on what I'm doing wrong or how popups are supposed to work with respect to auto layout?
Something to watch for with popovers is that on devices like the iPad, the size class for the popover is not the same as the controller which raises it.
You will probably find that the size class goes from regular width to compact width when you use a popover on an iPad. If you have layout coded to regular width for your popover content, then it will not work in the popover.
The size of the popover itself comes from the content size properties for the controller presented. You can set this size explicitly in the attribute inspector for the view controller or in code. See: How to present popover properly in iOS 8
To make the elements display correctly on screen, change the size class control to Any-Any (near the layout toolbar at the bottom of the Interface Builder canvas) before adding elements in the Storyboard in the View Controller that will act as a popover.
I have an iPad popover containing a scrolling text view that is initiated via a custom toolbar button item through a IB defined segue. Upon device rotation, the size of the popover is changed in code via the popoverContentSize property to handle the changes from portrait to landscape orientation and vice-versa. The scrolling view contains a number of equivalent pages of attributed text that is programmatically added to the scrolling text view.
All of the text appears just fine when in the portrait orientation, but when I change to the landscape orientation the last paragraph or so of the text does not appear in the rotated scrolling text view. What am I missing or not doing? How can I make all of the text appear in the landscape view as well? I appreciate any advice that anyone can give.
You probably didn't change the frame of the textview when you changed size of the popover.
You need to make the frameSize and contentSize of the textView as dynamic based on the screen width and height (orientation) and refresh the values on rotation of device.
I need to have an iPad app that has a consistent toolbar at the top of the screen. I need it to adjust when switch from landscape to portrait. Essentially what I need is something that acts like a UINavigationController, but allows me to have an arbitrary number of buttons like a UIToolbar. I've seen this done, but I can't figure out how to do it.
Thanks
There is no reason you can't just use a standard UIToolbar at the top of the screen, rather than the bottom. This allows you to add as many buttons as you can squeeze on, and customise their appearance.
In order that it should adjust its size when switching interface orientation, you simply need to adjust its autoresizingMask property. This is easy in Interface Builder - just turn on the horizontal arrow in the middle of the autoresizing box (this makes the width flexible), and maybe make sure that the left, right and top struts are enabled to so as to hold it in the correct position.