ios - button not responding to click after I change its coordinates - ios

I have a button that I configure like this in my .h file:
- (IBAction)addBusiness:(id)sender;
#property (weak, nonatomic) IBOutlet UIButton *planBusinessButton;
then I do this in my .m file:
- (IBAction)addBusiness:(id)sender
{
NSLog(#"Plan business clicked 1");
}
- (IBAction)planBusinessButton:(id)sender
{
NSLog(#"Plan business clicked 1");
}
but in my onLoad I do something like this:
CGPoint pt = planBusinessButton.center;
pt.y -= 275;
planBusinessButton.center = pt;
The problem is that the button click is not firing in the IBAction when I click the button.
Would the changing of the location of the button have an effect on why the button is not getting clicked?
Why would the button click not fire in the IBAction?
Thanks!

EDIT: Moving the button should not affect it's action firing, unless it's moved off the view or being below some other view that would intercept the tap.
If tap is not firing the button, check that:
IB connections are properly connected
methods exist in the proper location
button is enabled for user interaction
Try to avoid doing any view modifications in viewDidLoad method, as the view is not ready yet...
instead, try setting the button center in viewDidAppear method.

Possibly. Gesture Recognizers could be handling the events in the location the button moved to or there could be another view blocking the button at the new location and you need to bring the button to the front. Also, you should put this into viewDidAppear or an IBAction if you want an event to trigger it.

make sure that your planBusinessButton.frame is not outside its super.frame .
eg:if the button`s frame like this (0,-200,100,200), when the button added to its super view it will not handle the click event.

Related

How to disable fast touches and double opening view?

Please help me with problem -
I have button, or label, or textfield at UiViewController view, which have method to open another view, if i touch it.
But if i touch button, label or textfield very fast, it can open two, or three, or more same views.
How to disable this opening? How to open only one view?
How i can do this for all project?
Thanks!
when you click on button then Calling method of the Button, Inside the button method you disable your button, and after when you dismiss open view then again you enable your button.
-(void)YourButtonMethod
{
YourBtn.enable = false;
}
// Enable your YourBtn when dismiss yourView.
It is usually easier to disable the UIButton when you enter the function and re-enable it before leaving. Would look something like this function
-(void)buttonTapped:(UIButton *)aButton
{
aButton.enabled = false;
// do your work here
// and before leaving
aButton.enabled = true;
}
But in your case you are pushing a UIViewController, so you should move the line aButton.enabled = true to your prepareForSegue function.

UIButton & UITextField will block UITableViewCell being swipe to delete

There are UIButton and UITextField in the UITableViewCell. The delete button will not come up when I swipe over UIButton or UITextField. I do search for the answers on SO and google, there is a similar questions Swipe left gestures over UITextField, but no correct answers.
I got this problem on iOS 8.
Edit
After setting self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;, it works perfect for cell with UITextField. But when i drag start from the UIButton, the delete button shows and the UIButton fired, which I do not want the UIButton get fired.
I don't know how to prevent the UIButton from firing in the first place, but UITableViewCell has the property showingDeleteConfirmation that can be used to check whether the Delete button is being shown. What I do is check this in the UIButton action for TouchUpInside, like this
- (void)buttonPressed:(id)sender
{
if (!self.showingDeleteConfirmation) {
// Handle button press
}
}
(This example is from a UITableViewCell subclass, so it uses self to access the property.)
This, in addition to the
tableView.panGestureRecognizer.delaysTouchesBegan = YES;
that you already have, works to get the swipe properly recognized and the button action not performed.

Swift UIScrollview double tap uitbutton zoom

I have a view hierarchy like this:
UIView -> UIScrollView -> UIView (contentView) -> UIButton
I have added code to the UIScrollView to activate zoom when the user double tap.
This is working well, the content view and the UIButton are zooming.
In my content view, I have some UIButton, my problem is when I double click on this button, I want the scroll view to zoom (this is ok) but I don't want my button to fire the event (this is not ok)
I want the button to only fire an event if the user click on it one time, but not with double tap.
In my case, the UIButton can be small, and I want the user to get the possibility to double tap on it to zoom, but to fire an action only if it is a one click.
I try to do this with swift
thanks a lot for your help
Instead of UIButton, use UIView or UIImageView as button and add UITapGestureRecognizer to it.
And implement the following logic:
if the view is double tapped {
call your zoom function
}
if the view receives single tap {
then perform your button click function
}
Hope it helps :)

Change image when button is pressed

In the app I have six buttons and when any of these buttons are pressed I want the image in the center of the screen to change to a different image but just for the time that any of the six buttons are being pressed. I am really struggling with this and all help would be appreciated. I am using a .xib file. Thanks again guys I am tearing my hair out with exasperation.
Thanks!
You need to have a responder(s) in your viewcontroller that is linked to all the button(s) on the viewcontroller through interface builder. In IB, to link a button to a method make sure the method is in your viewcontroller.h file and also implemented in the .m file. Then go to the connections panel in IB (after clicking on the button) and drag a connection from 'Touch Up Inside' (touch up inside is when a user touches the button and releases that touch up and inside the button's boundary) to the viewcontroller.xib window onto the file's owner icon. From there you will be presented with a drop down menu that will let you choose the IBAction methods you specified in the header file.
In this case take:
- (IBAction) buttonPressed: (id) sender; // header file
- (IBAction) buttonPressed: (id) sender { // .m file
// when the button is pressed then change the uiimageview
[imageView image: [UIImage imageWithContentsOfFile: #"image.png"]];
}

IBAction UIButton firing is delayed

I have a UIButton connected to an IBAction in Interface Builder.
The Problem:
The action firing and the de-highlight of the button both take a little bit to happen.
The Facts:
View structure:
View
10 Buttons (connected via UIControlEventTouchUpInside to the IBAction
View (Subview)
Gesture recognizer
Text Field
The Subview has a UITapGestureRecognizer, which delaysTouchesBegan and delaysTouchesEnded both are set to NO
The action is happening in the main thread.
Testing a simple button (with no images or title, and only a simple NSLog), the result is the same
The Question:
Why are firing and the de-highlight delayed?
In the end, I added somewhere some UIGestureRecognizer, and forgot to set delaysTouchesBegan to NO =(
Ok I think that because of the UITapGestureRecognizer .. try to do the following :
connect an IBOutlet to your button.
2.assing the UITapGestureRecognizer delegate to your ViewController.
3.Implement this gesture delegate method in yourViewController
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
return (! [yourButton pointInside:[touch locationInView:yourButton] withEvent:nil]);
}
This will make the tap to be recognized to your button not to the recognizer.
Make sure your touch event is set the first contact of the button which would be the touch down event otherwise there will be a delay in the action until whichever other event you chose gets completed (i.e. touch up inside, touch up outside, etc).
In my case, there was a delay on IBAction for a button that was in a custom CalloutView of an MKAnnotationView.
In the same way there is a ~0.5sec delay between pressing the MKAnnotationView and the MKAnnotationView actually being selected, there is also a delay between any other user interactions you might add as a subview of the MKAnnotationView.
The solution is to disable the native UIGestureRecognizer within MapView that is causing the delay of any MKAnnotation view selections.
This can be done with the solution on this post:
Set isZoomEnabled = false within a gesture recognizer attached to the mapview on any tap, then set isZoomEnabled = false within a 0.5sec async dispatch.

Resources