How to have two subviews interact with each other? - iphone

I have a subview layering problem where I have a rotating arrow and a UIButton. The arrows rotate and the UIButton changes depending on the rotation of the arrows. The problem is that I need to have the UIButton clickable. At the moment the arrows rotate but the UIButton is not touchable. If I try [self.view sendSubviewToBack:wheelControl]; the arrows are sent to the back and are no longer visible.
thanks for any help about how I might fix this.

You need to call
[theView bringSubviewToFront:theButton];
as the last call when laying out your subviews.

Related

How to move UIView outside its SuperView?

So, I have a custom UIView inside a UIScrollView. I am able to detect the touches Events in the customUIView. I am trying to drag the UIView outside the UIScrollView onto a Canvas (UIView). However, when it gets out of bounds from the SrollView, it just hides behind it? How can I overcome this? Thanks guys!
When you start dragging the view, remove it from the superview that is the UIScrollView, and make it a subview of the app's Window, and bring it to front (z-order-wise).
But first you need to calculate (convert) the dragging view's frame with regards to the window, since the coordinates will be different after changing its superview.
you can use this method [UIView removeFromSuperView];

How to blink a touch area in UILabel iPhone?

I have an UILabel. I want to glow the touch area in it. That is, when I click on a point in that UILabel, a small circular portion around the touch point should be presented with glowing effect. How can get this?
Well you can do that by creating a CALayer or a CAGradientLayer based on how you want your glow and add it as a sublayer to the label's layer at the location of the touch.
For enabling the touch on UILabel, look at userInteractionEnabled property. You will need to set it to YES.
Then you will need to attach a UITapGestureRecognizer to the label for getting the tap. Once you have the touch location, add the custom glow layer as a subview to the label's layer in an invisible state. Animate the glow layer in and out. You might want to repeat a few times before removing the glow layer as a sublayer at completion.
UILabels don't respond to touches.
Use a UIButton with a custom type and provide images for the normal state and the (glowing) highlighted state.
Gesture recognizers are nice, but if you want to do something that starts when the finger touches, stops when the finger stops touching, and moves around with the finger in between, then it's hard to think of a good gesture recognizer for that. I think in that case you'd be better off just using touchesBegan, touchesMoved, and touchesEnded (don't forget touchesCancelled).
You can either put those methods on your view controller or subclass UILabel. Either way, set userInteractionEnabled = YES on the label.
As for how to graphically make that effect, I don't have any clever ideas for it at the moment.

iPhone SDK - Touch a UIButton through a UILabel

I am trying to capture a touch through a UILabel, but am having trouble. Here is my scenario.
I have a UIButton as a subview of a UIScrollView. I also have a UILabel as a subview of the same UIScrollView. The frame of the UILabel overlaps that of the UIButton, and thus (as far as I can tell) occludes the UIButton from being pressed.
I am trying to create a scenario where the user can touch through the UILabel (it has a transparent background, so the button is completely visible - less the labels text).
Is this possible?
I know touches behave differently when there is a UIScrollView involved. Is that impeding the touches?
Anyone have any advice?
Cheers,
Brett
myLabel.userInteractionEnabled = NO;
Creating transparent UIButton on top of UILabel that too inside a UIScrollView is a design issue for me. If you have to do it then you don't have a choice. It won't work seamlessly though. Don't expect users not to complain. If I don't see a button there and scrolling through the view accidentally triggers button action then I am irritated.
It is possible to create such UI.

How to pass a 'tap' to UIButton that is underneath UIView with UISwipeGestureRecognizer?

I have a UIButton underneath a (transparent) UIView. The UIView above has a UISwipeGestureRecognizer added to it, and that is its only purpose - to detect certain swipe gestures. I want all other touches to be ignored by that UIView, and passed to other views (such as my UIButton underneath). Currently, the UIView above seems to be detecting the tap (for example), doing nothing (as it should be), and not letting the UIButton underneath get a chance to respond.
I would prefer not to implement my own swipe recognizer, if possible. Any solutions / advice? I basically just want to know how to tell a UIView to pay attention to only a certain type of added gesture recognizer, and ignore (and thus let through to views behind) all other touches.
Have you set:
mySwipeGesture.cancelsTouchesInView = NO;
to allow the touches to be sent to the view hierarchy as well as the gesture?
Additionally, ensure that the view on top is:
theTransparentView.opaque = NO;
theTransparentView.userInteractionEnabled = YES;
I've had pretty good success attaching gestures to the parent view without needing to create a transparent subview on top for the gesture. Are you sure you need to do that?
I must have just been in a funk yesterday - I woke up with a simple solution today. Add the UISwipeGesture to a view which is a superview to both the UIView and the UIButton. Then, when processing those swipes, figure out where the swipe originated, and whether that point is in the frame of where I used to have the UIView. (As I mentioned, the only reason for the existence of the UIView was to define a target area for these swipe gestures.)
Can't you put your button on top of the view and add gesture recognisers to that button too?
In the end, your UIButton inherits form UIView via UIControl. Therefore there is practically nothing that you could do with a view but not with a button.
In my case, I fixed it by not using a button, but rather a UITapGestureRecognizer. My pan gesture recognizer was added to the background view, and the tap gesture was added to a view above it.

Dilemma with buttons within UIScrollView

I've got a UIScrollView (scrollView) and a UIImageView (scrollImage). I'm trying to add buttons to a scroll view and have them resize and reposition correctly when I zoom in and out. I had the following code at first to add a button:
[scrollView addSubview:button];
This gave me problems with zooming in and out. The position of the buttons wouldn't stay relative to the image. So i changed it to this:
[scrollImage addSubview:button];
Which made everything zoom in and out nicely, however the buttons have stopped reacting to touches (I assume because they are beneath the UIScrollView).
Is there a way to have both features working correctly?
Thanks
Zac
By default a UIImageView has userInteractionEnabled set to NO. Set it to YES and you should be fine.
try by setting like this,
scrollImage.userInteractionEnabled=YES