I'd like to disable a button interaction if it is below another view.
On this example, my UIButton is the green frame.
I can tap on it and it will call the right selector (with control event "UIControlEventTouchUpInside"). But this call also work if I tap on the red frame which is above the green button, and I don't want that...
Any help to disable the interaction where the button isn't visible?
Fixed by setting :
theUpperView.userInteractionEnabled = YES;
Related
Right now I have a square button like so
OFF
ON
I want the button to change instantly when I first press on it (not wait for the finger to be lifted), so I need it to fire instantly and only once because I will also include a long press gesture for a different action. How would I go about making the button behave like this? Right now it only works for when I lift my finger off. (all the config has been done in the interface builder).
EDIT:
As liushuaikobe explained below I have set the event to "Touch Down" now. The button is now firing correctly but the image won't change until I take my finger off:
- (IBAction)pressButton:(id)sender {
NSLog(#"button pressed");
button.selected = YES;
}
The button should be selected instantly, I have the off image set in the interface builder for default and the on one set for selected. Any ideas what I'm doing wrong here?
Add a action for the button on state UIControlEventTouchDown.
This is the state when button is "pressed" rather than the finger left the screen (which is called UIControlEventTouchUpInside).
Connect your button action to your file owner with Touch Down event like this:
if your button connected with IBoutlet then you can do it by this way
[switchButton addTarget:self action:#selector(forgotBtnClick:) forControlEvents:UIControlEventTouchDown];
Set an image for the state highlighted:
[yourButton setImage: yourImage forState: UIControlStateHighlighted].
Set your highlighted image (UIButton's property) as on.png, assuming that default is off.png only if you want the effect not the method to be called, if you need your method to be called on press down then you have to change your control event from UIControlEventTouchUpInside to UIControlEventTouchDown
http://youtu.be/TzPk4_hKozs
In this video, I made 5 button on view control.
When I touch button1 , it is highlighted.
I move my finger to button2 button 3 button4 button5...but there are no highlighted.
I wanna let the button highlighted when I move into their bounds.
How can I do?
please help me, thank you so much.
You won't be able to get that behavior with UIButton, but you can get it with not a lot of work.
Create a UIView subclass that can be set to be highlighted or not.
Add a UILongPressGestureRecognizer to the view displaying all 5 of the new views.
Specify an action and create a method to match, like -(void)longTouch:(UIGestureRecognizer *)gesture.
When the gesture state is UIGestureRecognizerStateBegan or UIGestureRecognizerStateChanged, determine what view your touch is over and highlight that view and unhighlight the rest.
I am dynamically creating a uiscrollview and i place some uiview's that contains some label and buttons inside to display some news. Every button inside the sub uiview calls a rest function to like, unlike or share the news. Some of the buttons opens overlay screens like comment news. I am assigning actions to buttons inside the main form that contains the uiscrollview.
When i click a button that opens an overlay screen. When i close the overlay screen and hit Like button, it does not respond to touches. After attempting one or two more times, it works.
Does anyone has any idea about this issue?
Are you using UITapGestureRecogniser for "Click action"? If yes, you propably want to set flag "cancelsTouchesInView = NO" for this recogniser.
Check to see if there is a clear view covering your button. That view will consume your tap, so the button never sees it.
My ViewController contains WebView and invisible button over (or below) the WebView. (see image). I want that the button to be clickable. But(!) in the case there are some links in the WebView, the links should be clicked, not the button.
How can I do it?
Similar issue discussed here:
Add UIButton in a UIWebView
However, in my case, I need links that are clickable also not be scrolling enabled.
If all you need is to be able to still drag the UIWebView around while still being able to receive a button press on a certain part on the view, you don't need to place a button below it in order to achieve that.
UIButton can still be able to receive touch even if it is completely transparent.
yourButton.backgroundColor = [UIColor clearColor];
[yourButton addTarget:self action:#selector(pressed)forControlEvents:UIControlEventTouchUpInside];
This way the button would only receive the press and will not affect your dragging of the web view - it will ignore the dragging but respond only to the press.
Tested on a scrollable view with a clear UIButton.
Hope this helps.
I have an view which is having a button and a label.
The label increments whenever the user adds items to the cart, which is done by using custom badge. But what I need to know is how to put onClick for that label. Button takes the onClick but label is not taking an action(UIGuesture).
I have attached the image where in clicking on the cart goes to another view, but clicking on label does not work.
Any help would be appreciated.
thanks.
Try enabling the user interaction on label.
label.userInteractionEnabled = YES;
By default user interaction is disabled on UILabel, which doesn't let any gesture to be recognized while applied on UILabel.
Better to use an open-source implementation:
MKNumberBadgeView
CustomBadge