Button and Slider Stop Responding After Rotations - ios

I have a test app that uses a custom container controller to switch between 2 child view controllers based on the orientation of the device. In the portraitController, I have a button and a slider -- after one rotation to landscape and back to portrait, the slider still works but the button doesn't. After one more back and forth, both UI elements stop responding to touches.
Meanwhile, in the landscapeController, the button works fine for the first 6 times you switch to that controller, but on the 7th, the button only responds on the far left side, and on the 8th, it no longer responds at all.
The views look fine after the rotations -- everything stays in the right place. There's no methods connected to these UI elements I'm just seeing if they are responsive to touch. I have strong references to both child view controllers, so I am presenting the same instance on each rotation. I can post the code for the container controller if it would help.
Does anyone know what's going on here?

I found the answer after much experimenting -- the "Autoresize Subviews" check box in the container controller's view needs to be deselected. I'm not sure what that does exactly, but it was inappropriately resizing the views of the child controllers.

Related

Buttons inside container view does not work

I am a total noob developing iOS applications and I'm working in one right now.
I have set up my storyboard with a HomeViewController (main) and inside this, a container view, with another view controller embeded. This child view controller is outside the bounds of the view, and when a click a button in my HomeViewController it gets animated to the top of my app, showing this child with a cool animation. Everything is right.
In my child view controller I only have 3 buttons, and when they are displayed on the screen with this little animation, they are not usable. They don't trigger the action of the button being pressed nor they get "highlighted" with iOS style. Nothing happens.
I have been searching a lot about this, I have tried addChildViewController() on parent, didMove(toParentViewController: UIViewController) on child and I also have added it programmatically. When added programmatically it works OK but the view does not respect the animation, just being displayed in the screen without following the parent's container, which indeed moves with the animation.
What should I do next?
Thank you very much
Edit: My question does not seem to be a duplicate of UIView animations canceling any touch input
I'm using Spring library for the animations. Also, in that thread they are talking about user interaction being blocked while animation isn't finished. That is not my case. Animation is perfectly finished when trying the button interaction.
From my experience, there are two issues which cause this behavior most often:
Some of your container views have userInteractionEnabled set to false, or
Your container view frame is small and you're attempting to tap a button outside the frame of the container which won't work. Consider it like a window to the button and there's an invisible wall blocking touches.
Both of these are best debugged using the Xcode Debug View Hierarchy, or you can also try the Reveal app and see what's going on there.
Finally, this misbehavior was because the wrapping view in my container was smaller than the container, but as these two were out of screen I didn't realise at first. Making the wrapping view big enough to fit the child container was the solution.
Sorry because at last this was a stupid question.
Thank you all
If you use auto layout. You may check out your constraint is correct or not. Especially for biggerOrEqual and smallerOrEqual constraint still need a concrete constraint. eg:
width = 100#750
width <= superView.width#999
You should not forget the first constriant.

Organizing my first iOS app's UI

I'm making an app for my Independent Study, and I have a UI functionality in mind - I just don't know how I would go about implementing it.
It's very simple in theory.
I want to have an initial view that fills the screen. When the user swipes up from the lower middle part of the screen, I want to do something that acts similar to control center, but for it to be a view that allows for me to choose between each of the 7 days in the upcoming week, displayed as icons with tags, and the user can swipe through them similar to how one swipes through the pages of apps on the home screen.
Similar to control center, the view should animate by sliding in from down to up, take up only part of the screen (In my case, about 1/5 of the screen as opposed to control center taking up more than 1/2) and the view behind it should of course remain running.
I am a beginner with iOS trying to get on my feet.
My question really boils down to this: I am unsure of what View class to use in interface builder for this, and whether or not this requires a segue/new view controller.
My initial thought was to drag and drop a View into the top level view, set its boundaries to how I want it to end up, then set it to hidden until I handle a swipe up, at which point it animates by sliding up.
I have done my best to describe my question but I am willing to clarify further if needed.
You can use 2 scenes in StoryBoard.
One as the mainView and one as the controlPanel.
Design as you like. You can detect user calling it by using UISwipeGestureRecognizer. And call the segue to that controlPanel scene.
On the controlPanel scene, you should set the backgroundColor to clearColor, and add another UIView on it with blackColor and alpha 0.5f.
To present it above the mainView, use modal presentation.

How to get a parent view to recognize rotation in subview ios

I have two viewcontrollers. When the user clicks a button, the parent vc uses presentviewcontroller to call the subview. The problem I am having is when the user rotates the iphone in the subview then closes it, the parent view does not fit the whole screen (it turns to landscape but only displays on half of the screen). Is there a way to let the parent vc know it needs to rotate when it happens in a subview?
Also note that the parent view rotates perfectly when the rotation takes place in its view.
Your problem may be related to this previous [question][1]: View rotation notifications: why didRotateFromInterfaceOrientation: doesn't get called?
But I am also a bit unclear about your terminology. I think you're using sub-view to refer to a subordinate VC, rather than a subordinate in the View Hierarchy.
Since you have two VCs you need to make sure that rotation handling code is present for both, and that the handlers are receiving the notifications. I suggest putting in diagnostic code in the rotation handlers for both VCs to see which is being called, and when - that should give you enough information to solve the problem or at least to post a followup.

UITableView tracking touches on wrong axis

I have a uitableview controller which is a subview to a view managed by a uiviewcontroller. nothing really out of the ordinary but the tableview tracks gestures on the wrong axis(only on device).
Basically you scroll up/down table doesnt do anything, and left/right scrolls table up/down. its super weird. i was hoping somebody has seen this before and maybe know what causes it?
Edit: heres a video
http://c.drunknbass.com/EB7m
at the end i am scrolling a uiscrollview that scrolls normally and is a child of the same uiviewcontroller.view
UIKit relies on there being a key window, and that window having a root view controller, to be able to correctly handle events, and forward them to your code. I suspect that perhaps one of those things is not set up correctly in your app. (Such that the device orientation isn't matching up with the visual orientation of your UI.)
Also note that prior to iOS 5, making one controller's view the child of another controller wasn't really supported by UIKit. It can be done, and mostly works, but you are going to have to manage the forwarding of all of your lifecycle events. (See the notes on controller containment in the docs, and the description of -automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers as well.)

How to properly switch UIViews

I want to have multiple views in my application that I switch between.
What is the proper way to switch between UIViews that also supports UISplitViewController?
Is there a support way to switch or are Apple's controller classes designed to be root and root only?
I've tried having one root view and root controller and swap subviews in and out. One of the subviews is a UISplitViewController. It did not like the arrangement and does not display correctly. The detail view was not displayed, the master view displayed wrong orientation and wrong size.
I've then tried managing adding and removing one subview from the UIWindow in the app delegate. This works most of the time. However, the views added after the applicationDidFinishLaunching method do not appear setup correctly. They mostly look correct, however sometimes the orientation thinks its portrait when in reality its landscape. Also, when I try to display a popover, it shows up in an incorrect location. If I change the orientation, it redraws correctly. I've also have some random instances where the UISplitViewController view does not fully display, as if its frame is incorrectly sized.
Any suggestions heartily appreciated.
In applicationDidFinishLaunching, your objects haven't completed loaded from NIBs yet. Try using a viewDidLoad method instead.
What is the user-interface for switching between views? If one of these views represents a transient mode that the user enters and then exits, consider using a modal view. (See presentModalViewController:animated:.)
I would need more details about what you're doing to answer more particularly.

Resources