UITableView portion loses interaction after device rotation - ipad

I have a UIViewController with a UIView subclass as a subview, and in here is a UITableView added as a subview of that UIView, as follows:
UIViewController
-UIView
--UITableView (plucked from a UITableViewController)
On an iPad, if I load the view controller in either orientation I can interact with the table view perfectly. However, if I rotate the device to a new orientation - I have code that alters the frames to make it fit the new resolution, but a small area of the table does not respond to touches and whatnot.
eg, we rotate portrait to landscape: if you imagine a portrait shape placed over a landscape screen - this area remains responsive, but a small strip to the right hand side does not respond.
Does anyone have any ideas what I may have missed? Thanks in advance.
EDIT: I have successfully verified the CGRect frames of all objects from the tableview cells through to the top UIViewController.

The area that looses its interaction must have fallen outside its superview's frame after rotation.
you can check that by setting tableView.clipSubviews = YES;
using this, will crop the tableview portion falling outside the superview.

Related

Parent UIView in StackView displayed wrong, but its subviews are correct

I have a problem where the frame/layer is shown correctly on iPhone, but not on iPad and iPhone X. Only after going to another view and back to that UIViewController it is shown correctly.
I have a 3 UIViews in a vertical StackView. The first top 2 are shown correctly. But the third is not. The third UIView contains a containerView and in it there is a TableView. Through the view debugger I can see that the containerView and the tableView have the correct frame, but it looks like the parent UIView is not redrawn correctly.
Here is a screenshot of the view debugger from the front of that UIView. The UIView with the red background is the one displayed incorrect (correct after going away and back to that UIViewController).
UIView with red background incorrect (Frame is correct, but displayed wrong). The subviews have the correct frame. I set a backgroundcolor to those subviews and these are redrawn correctly
Here the same view from the back:
UIView in question from behind
I tried .setNeedsDisplay., .setNeedsLayout, followed by .setLayoutIfNeeded. Running those in main thread, but didn't got success so far.
I am using Swift 4 and iOS 11. As I said this is in a vertical StackView. The first 2 UIViews have a height constraint, this one, has no constraint as it should fill the rest.
Any help appreciated!
The problem was solved for iPad and iPhone X, removing the shadow layer on the view that was drawn incorrectly.

Unresponsive area in UITableView in landscape orientation

I'm developing an iPad application where I have a screen with UITableView hosted on UIScrollView. UITableView's leading space and trailing space is being pinned to superview.
I'm using Autolayout in my project.
When this screen appearing in landscape mode or rotated to it all visible elements of UITableView being resized correctly. However area after x=768pt is being untouchable. It's definitely area because beginning of editable elements (text view and text field) are being touchable.
I checked contentSize of table, it's being OK (1024 in my case).
Also when I rotate iPad from landscape to portrait contentSize of table still stays landscape (1024). I tried solution from this topic: bug in UITableView layout after orientation change and it worked. Don't know if this is connected to my issue.
I tried to place regular view instead of my UITableView. On this view after rotation touch area was OK. However when I placed my table on this view right area still was unresponsive.
Table's property clipsToBounds set to YES so it seems that content is not becaming outside of UITableView.
Please point to what may cause this issue. Right now I'm completely out of ideas what may cause this.
I found a solution. The problem was in overriden method -(void)layoutSubviews in my custom cell. I simply forgot to call [super layoutSubviews] in it.
Never forget to call [super layoutSubviews] in any non-standard view.
Hope my solution will help someone not to waste hours on simple issue.

iPad orientation issue. When does the app begin to know about its orientation?

I am implementing an application which is locked to landscape only, containing a UIScrollView (the super view to add sub-views) and a UIPageControl.
When I trying to add a sub-view in viewDidLoad, calculating its frame by referencing its super view's frame, it is always portrait.
But the sub-view added later (say in the scrollViewDidScroll, when user swipes to next page) is landscape.
I set a break point and found that the super view's size is 768*969 in viewDidLoad and 1024 * 713 later.
I suspect it is because the app doesn't know about the orientation at all when viewDidLoad thus everything is default to portrait layout. Am I right?
If so, when will the app know about the orientation for the first time?
Thanks.
The workaround I found was to reparent the scroll view under an intermediate view
VC
view
view (intermediate view)
scrollview
Then the frame of the scroll view was correct in viewdidload (previously without the intermediate view, the frame was in portrait right up until viewdidappear!)

Auto resizing UITableView on rotation with flexible width

I am adding UIButtons to a UIView located on the right side of a split view controller. Without any autoresizing set, the button text fully displays in landscape orientation. When I rotate to portrait orientation, all button text is fully displayed, but there is extra space on the right hand side of the UIView, because there is more real estate to work with.
I would like these buttons to resize on rotation so that it utilizes the entire width. I tried setting:
[button setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
With this in place, the same extra real estate exists on the portrait orientation, but in landscape orientation I get a lot of buttons with the text shortened with "..."
How can this be done?
when the AutoResisingMask doesnt do it for me, I always resort to subclassing the UIView and overriding the layoutSubviews... this way I can manually place those tricky views that never look right in different orientations.
in fact.. at last year's WWDC, I heard an Apple Engineer say that he "always" creates and adds his views with frame CGRectZero, then sets the correct frame in layoutSubviews. For what its worth...

UIScrollView dragging affected by UIWindow transform rotation

I'm adding a video out function to my iPad app and have run into a problem with my UIScrollView. To get the proper view orientation on the external monitor, I've rotated the UIWindow based on the current interface orientation (e.g. - mirroredScreenWindow.transform = CGAffineTransformMakeRotation(- M_PI * 0.5);).
The problem I've run into is that the ScrollView dragging seems to be affected by the UIWindow transform. If the UIWindow is rotated 90 degrees, horizontal drags scroll the view vertically and vice versa. Is there any way to correct this?
I got a response from Apple Dev Support that said essentially, "Doing a transform on UIWindow will confuse the internal objects and should never be done."
Looks like I'll just have to create a modified ViewController that lays out all of my UI elements specifically for the format of the external screen, rather than just transforming the view controller that already works correctly on the iPad screen.
Scroll views seem to maintain their own hidden transform. You can try examining it, and see if there's any difference between when instantiating and adding the scroll view before or after modifying the window transform.

Resources