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

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.

Related

Hide non child UIView in UIView

I want to hide a non child UIView in a UIView but I don't know how to do it.
To be specific, I have a UITableView. Each UITableViewCell has another view inside it (a wrapper view called wrapperView). The wrapper has some labels set up in IB and some created programmatically. I have created a custom slide mechanism that reveals buttons under the wrapper (like the standard one does).
The labels created programmatically don't exceed wrapper's bounds because it clips the subviews. The problem is with the labels created in IB. They are the subviews of contentView.
How can this be solved? Is there a way for a UIView to clip other views on the same level(not parents nor children)? Or "transfer" the labels to the wrapper view?
It isn't completely clear what you're asking. A view will only clip it's subviews, not views that happen to fall within their frame rectangle but aren't subviews.
If you want to move a view object from one view hierarchy to another you can use addSubview(_:) to do so. That will automatically remove it from it's current parent view. To quote the Apple docs:
Views can have only one superview. If view already has a superview and
that view is not the receiver, this method removes the previous
superview before making the receiver its new superview.

iOS: How can I remove reference to sub-views?

I'm creating an app that has hundreds of view controllers in interface-builder. Each of these view controllers has a button with a code number. When the button is pressed I want the button to expand and show a few lines of text describing the code number. The problem is that the button is placed within a subview that acts as a frame for the button. Therefore, the expanded button size is going to be constrained to that subview and the text will be cutoff. Is there a way for me to programmatically remove the reference to the sub-view? I can do this in interface-builder, but like I said there are hundreds of these view controllers.
Instead I removing it you could expand the subView's and the UIButton's width. That would allow the button to expand as you'd like it to and you would not have to remove the subViews.

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.

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

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.

Moving objects in Xcode without adding to underlying object

I'm trying to move object in Xcode's storyboard editor, but I can't find the key combination to use so that the object does not het appended to underlaying view.
My case:
TOP
Button
SubView - UIView
Image
Label
BOTTOM
I'm trying to move the button, but Xcode automatically adds it to SubView, so result is like:
TOP
SubView - UIView
Image
Label
Button
BOTTOM
I'm animating the SubView on Button tap, so Button can't be in the SubView.
Is that possible without manually selecting the object in object tree and editing position manually?
While you're dragging your button down to the bottom of the object list, once it's in the vertical location you want, drag it left. Like, further left than you think you should have to, until the correct parent view is highlighted.

Resources