I have a button and half of the button is covered by a UIView (for styling).
I was wondering if there was any way to make this UIView "touch transparent" as it were, so if you press on it it lets you select the image behind it?
Or will I just have to make it a button itself?
Thanks
Tom
You should set the UIView's userInteractionEnabled property to NO.
try to make the UIView opaque to NO
Related
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.
I have subclassed UINavigationBar and overridden drawRect method so I can add a gradient to it. Now, I want to use the same gradient to the back button, but I don't know what is the easiest way (subclass UIButton, subclass UIBarButton item)
Thank you.
A lot of people on StackOverflow caution against subclassing UIButton.
create uibutton subclass
The easiest way to do what you want is to use [UIButton buttonWithType:UIButtonTypeCustom].
Make a transparent .png image of your button and set it as your button.image.
You can have a look here:
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
explore: http://idevrecipes.com/2011/01/12/how-do-iphone-apps-instagramreederdailybooth-implement-custom-navigationbar-with-variable-width-back-buttons/
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.
I have a subview on the screen that is loaded from a XIB, I need to disable touch events ONLY on its superview while not touching the subview in the end. How would I do this?
Also, I am using iOS.
Thanks!
This is how you can go about doing this -
Go to interface builder & select your superview (for which you want to disable touches).
Open right navigation bar. At the bottom there is a checkfield called "User Interaction Enabled". You can unmark it. Of course you can go about doing this from code too. But this is more graphic. This screenshot might help. See bottom of the image...
I am also new to iphone development but htis piece of code helped me out when i tried to move only UIImage view.
you can apply cahnges on this code if you are using buttons or labels in your view.
if ([touch.view isKindOfClass:[UIImageView class]])
{
imageDemo.center = touchLocation;
}
In XIB, rather than using all other views as subview, u can just use superview at same level and set its usertouch interface as FALSE.
Please look at this screenshot:
When you tap in another segmentedcontrol, it switches smoothly (try it if you can).
First of all, is it a segmentedcontrol?
Second, how can I add this smooth effect?
Thanks guys.
I just tried. It does not seem to be a segment view.
Maybe 3 dark buttons(or view or views) and a layer that moves and overlay the current selected button.
Everything is well crafted so it looks great ;)
I think I could do that with a big UIImageView (instead of the three buttons) with an UITapGestureRecognizer to get the touch and a CALayer for the selected button