How to get a parent view to recognize rotation in subview ios - 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.

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.

Present view controller while touching

I want to implement a hold-to-preview button that brings up a view containing an AVPlayerLayer, which plays as long as the touch doesn't end. The video player is contained in a different view controller, and I am hoping to be able to use presentViewController:animated: when presenting it, and not just add it as a subview and child view controller.
My question is about how to deal with the touch event. I see two possible ways:
I try to transfer the active touch down event to the presented view controller (not sure if even possible), or
I try to keep the original view controller's gesture recognizer active, and then let the video view controller know when it's time to dismiss itself. I'm hoping this could be achieved either by just setting the presented view controller's userInteractionEnabled to false, or perhaps using a UIViewControllerTransitioningDelegate to present it, and then just skip calling completeTransition: or something similar (I believe touches don't register on the new view until you complete the animation, but please correct me if I'm wrong).
My question is about how to deal with the touch event.
Touches are always associated with the view that they start in. You can't transfer the touch to a different view. I've never tried it, but the options I think you should explore first are:
Use view controller containment. Make your preview view controller a child view controller of the one where the touch originates. That way the parent and its view hierarchy never go away, although they could be covered up.
Attach the gesture recognizer to the window. A window is a view, and should be able to have gesture recognizers. You could make the gesture recognizer's target the app delegate or some other object that will always be around, and have the delegate post a notification when the recognizer is triggered. Again, I haven't tried this, but it seems like it should work.

What's the proper way to implement complex custom view controllers

Note: I'm not talking about custom view controller transition effects which can be done by using a custom view controllers it's the iOS 5+ API.
I'm talking about transitioning to another view controller, where a view from the presently displayed view controller is animated to the view controller to be presented's view.
EXAMPLE
-you have friendsViewController which displays a list of the current users friends. Each table view cell has a profile picture and name.
-click on a cell, all other cells fade away and the name and picture animate to the top. At this point, UserProfileViewComtroller is displayed.
THEORIES
-I could easily do this by combining the two view controllers, but UserProfileViewComtroller can be launched from other parts of the app.
-if the UserProfileViewControllers view is instantiated, I could convert the coordinates using UIViews methods
I feel like there is a more appropriate/cleaner solution here which is why I'm asking the community for help :)
It seems to me that what you want is exactly about view controllers transition, since you want to do 'something' that would look to the user as if you took a view from old VC and moved it to the new VC.
Then you're in luck, as you're allowed to move a UIView from one view controller to another using [superview addSubview:view] as part of the transition you want to do.
This can be done on any iOS version, although it's easier now as in iOS 7 there's a delegate you write (see <UIViewControllerAnimatedTransitioning> reference) which has access to both VC's view hierarchies and can change them at will (move one view, fade other views) during transition period.
Also, making your new view controller during the transition transparent (or using old controller's snapshot) will help you hide the fact that VC changed.
Not so much an answer but a technique that might inspire a solution. I did an app that had need for a custom transition like this. The original app arranged itself then took a snapshot, so at the last moment the user is looking at an image. The second viewController was created, given coordinates etc, and the image, then shown immediately. It put the image into its view (subview with same bounds).
At this point the second vc has complete control, and can fade in some other content etc. the reverse was more or less as the start - the image is used, swapped, used removed to uncover the real view content.
Note that this took a bit of time to get it working with no glitches etc.
EDIT: if you are concerned in turning the whole original view into an image, then modify the technique. For instance, in the original view, fade all other content to black but the cell, then snapshot the one cell. The second view will start with an all black background, and place the cell image over top it, then go from there.
EDIT2: As mentioned in the comments, you of course push the second view with no animation, so it happens instantaneously. By setting a small image on the second vc, with an agreed upon background, you can quickly "pass the baton" so to speak and let the second controller go to work quickly and seamlessly.

Button and Slider Stop Responding After Rotations

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.

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.)

Resources