I have a ScrollView which shows photos. When touching the screen, a UIToolBar pops up, with several UIBarButtonItem buttons, like Previous, Next, Play... If the users doesn't do anything for 5 seconds, the toolbar disappears again.
It's all very similar to the Apple Photos app.
Everything works as it should, but there's one thing I'm struggling with: I cannot get touches for if the user pressed the buttons, nor can I check on the highlight status of the button.
So there's a problem if the user keeps a button pressed for a few seconds... the program will assume nothing has happened, and remove the toolbar after the 5 seconds have passed.
The Photos app does not have this problem. Even better: when you keep the Next or Previous button pressed or longer than a second, it already executes the "action" associated with the UIBarButtonItem !
In short, I want to do one of these:
- to know whether a UIBarButtonItem is pressed
- to know whether a UIBarButtonItem is highlighted
- or else just know whether there's any press anywhere going on
You could try attaching a custom subclass of UIGestureRecognizer, which tells you when the users interacts with the view to the toolbar.
Alternatively, you could try subclassing UIToolbar and change its -[touchesBegan:withEvent:] and -[touchesEnded:withEvent:] methods to tell you when the users starts/stops interacting with anything on the toolbar.
The latter is probably simpler.
Related
I've been struggling with this for a while already and some
help would be useful.
Imagine I have a UIButton, which starts in highlighted/selected state.
If a user taps it, then highlighted/selected state changes.
I've implemented this and it works fine. Problems start
for example if user taps inside the button region,
does not release her/his finger, and moves mouse
outside the button area -- at this time my Button
would usually lose highlighted/selected state.
Anyway, I have solved this issue too, by overriding UIControlEventTouchUpOutside
and making button keep the state it had before...
But now another problem comes in, similar to the above,
if a user taps the button, does not release his/her
finger, and moves the finger to the right say (horizontally,
which also makes my dialog for instance go to the right),
then I again lose "selected/highlighted" state....
I believe again some kind of gesture similar to - but different -
than UIControlEventTouchUpOutside is being called which
removes my selected state...
Do you know what can be going in here? Any advice appreciated.
ps. I have fixed all the issues by just setting different images
for normal/selected states using the interface builder.
For the highlighted effect you can use the: setHighlighted of UIButton class.
When you start touching the button set the highlighted property of button to YES.
when you start touch:
yourButton.highlighted = YES;
When you stop touch:
yourButton.highlighted = NO;
I have fixed all the issues by just setting different images for normal/selected states using the interface builder.
I have a UIView with a lot of UITextFields on it and I want to close the keyboard when the user hits the done button. Setting a delegate on 20 different fields seems like overkill. Is there a way to get notified when they hit the 'Done' button?
Sadly, If you want a callback from any UI element - you'll need to be it's delegate.
My app has a screen where keyboard is always visible. The main element of the screen is a UITextfield. For easy data entering, keyboard is always made visible. When the user finishes entering data and hits Go, the app performs a 4,5 seconds action which is done in the background thread in order to show UIActivityIndicatorView.
My problem is that the Go button on the keyboard still shows as enabled since the logic is performed in the background. The user could potentially hit the Go again causing it to run again.
I am not able to set editable/userinteraction properties to No because then the keyboard disappears. Is there anyway just to disable the Go button or freeze the keyboard until the background thread returns?
You clearly already have a UITextFieldDelegate set up to handle:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField;
Otherwise, you would not be able to perform accordingly already. Just return NO from that function if the background process is running and the keyboard should not close. Example:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (alreadyPressedGo)
return NO;
...
}
However, this will not "disable" the Go button, simply disable its functionality.
I've not tried it (not at an OS X box at the moment otherwise I'd give it a go), but I'm wondering if you couldn't effectively disable it by placing a touch receiving UIImageView or similar on top of it. (You could even set the opacity of the UIImageView accordingly to achieve a greyed out look.)
This is combination with the disabling the operation of the button as #Skyler illustrated should be ideal.
When you touch a UIButton it hides for a fraction of second and then it executes its action. This fast "blink" is the feedback the user needs to know that the button has been clicked.
In the project I am doing, I need to select the button programmatically, as if the user had clicked it. In other words, the same behavior has the button had been clicked by the user... a fast blink and execution of its action.
Is this possible to do?
thanks for any help.
The change in the appearance of the button is effected by setting the button's highlighted property. The property is automatically set to YES when the user touches down on the button, and back to NO when she releases.
The highlighted property is writable, so you can set it YES yourself to simulate a touch down. You'll probably want to use +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] to set it back to NO after a short interval.
It is pretty simple, and probably there is a better solution.
First, use images to your button, and when you have to fire the button, you just change the button's image in the normal state to the pressed image, and after that, replace it back to the original. You can simply do it with a timer.
I am subclassing a UIButton and detecting finger movements, if the user swipes his finger in a certain way I will pop up an UIAlerView.
All good, except that after dismissing the UIAlertView... when the user next touches the UIButton the button goes to it's highlighted state and gets stuck there, continuously highlighted, even when no finger touching it.
Pressing the button again the UIButton begins to behave normally (only highlights when touched).
So I can only presume that an alert during a swipe, screws up the process of events, the touchesEnded never firing perhaps?
If anyone has any ideas on how to 'reset' the button after the swipe so that it behaves as it should, I would be grateful.
Are you resetting your state in touchesCancelled?