UITextField inside a UIView thats animated on touch dismisses the view and shows the keyboard - ios

I have a structure for my UIView object and have form elements within it. I run the application and the program is in such a way that when i click a button inside the UIView, it moves the current frame upwards. But thats not the problem.
My phonenumberfield is of type UITextField which is inside a UIView and that UIView is a part of the parent View. I have one button called submit and a segment control on the Parent UIView. But when i touch the phonenumberfield or any textfield type on the parent view, the parent view gets dismissed and keyboard shows up. Its weird I cant understand what the problem is because can't debug this. :(

I had a problem with the constraints for Auto Layout I had set for my scrollview and managed to fix the constraint and my view started scroll. To animate the view, I set a constant height from the top of the parent view and animated the view by changing the constant which did not affect the keyboard anymore.

Related

Animating UIView with auto layout when the view is just created and about to appear

I have a UIView that contains subviews that contains subviews...(Hierarchy of UIViews).
Every UIView is set with auto layout. When I press a button, this UIView is created and then I would like it to drop from the top of the screen.
The problem when I use layoutIfNeeded in an animation is that if will animate everything at the same time as it is a newly created UIView (not yet display).
My question is, is there a way to do the animation of only the UIView dropping with all the subviews already laid out in it?
I guess you can do it by creating the UIView when UIViewController displays and then hide it but I was wondering it there was another way.
Cheers
If you call layoutIfNeeded right after you add it to a view, while still outside the view, it should lay out it's views correctly. And then in the animation you call it again so the view animate to the final position.

UIButtons not working in Scroll View

I have a Scroll View with a View (content view) inside of it. I've added two buttons to test. The Scroll View scrolls fine but the buttons within the content view are not clickable. I've seen plenty of posts saying this issue happens when they programmatically add UIButtons to the View, but I am not doing this. Here is my exact process:
Drag the Scroll View onto the main view. Add 4 constraints
Drag the Content View onto the Scroll View. Add 4 constraints.
Add 2 Buttons (one high and one low to test scrolling) to the Content View.
This is all I am doing, no code at this point. Is there anything else I have to do to allow the buttons to be clicked? Here is a screenshot of my xib:
Update:
When hooking the button up to a simple IBAction and logging a message, it turns out it IS being pushed and working properly. However, when the button is pushed, the button isn't changing colors like it should (its "pressed" state is not appearing). Any ideas why?
First make the button to custom type
Select button from storyboard then on right attributed inspector change its "state config" to whatever you need like Highlighted, selected, Disabled and default and choose the colour for each state.
Now you can see the colour change on that button.
A UIScrollView first needs to know whether or not you are going to scroll before letting the touch pass to its child views. If you want the child views to get the touch immediately, set the UIScrollView's delaysContentTouches to NO.

animation not correct with implicit autolayout

I upload my demo code here:https://github.com/liuxuan30/Problems
The main problem is, I had a view which have a scroll view inside, and there is a label and collection view inside scroll view.
There will be a unread message button generated by code, when there is unread messages, the button will pop out, and I expect the animation: label and collection view will down-shift by the button's height.
When I test the animation without adding the button in subviews, animate as expected.
When I add the button in, it seems like the label and collection view's origin.Y up-shifted, and start the animation. Turning off auto layout will solve it, but I have to have auto layout. I tried to add constraints for all views, but the animation still not work out.
You can try comment out
[self.HomeScrollView addSubview:AlertView]; and self.UnreadAlertView.alpha = 1.0f; inside the code to see the animation.
Hope someone could figure out where i did wrong.
UICollectionView is already a subclass of UIScrollView. Embedding your collection view inside a scroll view may be what is causing problems with your animation.
Try removing your scroll view and just put your UIButton, UILabel, and UICollectionView inside your overarching view.

How to make UIButton overhang over parent view and still make it all selectable?

I have a UIButton which is a child of a custom UIView. I've placed the button so its center is directly on top of the top right pixel of its parent view. Currently only 25% of the button (the area of the button which is within the the parent's view bound) is selectable. Is there a way of making the rest of the 75% selectable?
Here's a link to a diagram of the problem
Thanks!
Since your button is a subview of the bigger parent view, touch events are not registered outside the bounds of the parent view.
I recommend that you add the button as a subview to the same view that the bigger view is in. You will have to convert the frame location to keep it positioned the same way.
UPDATE
You can convert coordinates automatically using the UIView convertRect:toView: method.

How can I bind a UIView's orientation to that of it's parent view?

I have a UIViewController, with a toolbar at the top. I have a few views that I'm going to be adding and removing, but I don't want them to cover up the toolbar. So I made another UIView, that fills the area beneath the UIToolbar, and am adding views thee, and it works great.
When I rotate the device though, the first subview rotates with the view controller, but the UIView inside of the UIView thats inside of the UIViewController doesn't rotate!
What can I do to make it rotate with the parent UIView?
PS- If you can think of a better way to do what I'm trying to do, I'm all ears!
EDIT:
To clarify, I have a UIView subview in IB, and that is all hooked up to the code just fine. Then, depending on the button selected, that UIViews subviews are removed, and then a new one is placed in the subview array. So I use addSubview to and removeFromSuperview to add/remove the view from the UIView that is a child of the UIViewController view...

Resources