I have a view that will have two kinds of tap gestrures attached to it.
Something like
view
.gesture(TapGesture().onEnded {...}) // <-- Don't fire this when shift is pressed
.simultaneousGesture(TapGesture().modifiers(.shift).onEnded {....})
How I prevent the first gesture to be fired when shift is pressed.
Under all circumstances I want only one gesture to be fired.
applying both gestures on view like .gesture does not work
The second one is not fired at all, under any circumstance.
Try to make second one with higher priority, like
view
.gesture(TapGesture().onEnded {...})
.highPriorityGesture(TapGesture().modifiers(.shift).onEnded {....})
Related
I have my code in Swift 3. I have two UITextFields and a UIButton in my view. I have the textFieldShouldEndEditing delegate of the first UITextField which is fired when I focus on the 2nd UITextField. However when I tap on the UIButton this delegate is not fired. I had thought that when a UIButton gets focus then the UITextField’s event will automatically fire since it is losing focus. However, when I tap on the UIButton, the cursor is still blinking in the UITextField, which means it is not losing focus.
Any ideas on why the UIButton is not getting focus will be most appreciated.
Thanks.
This is an infuriating aspect of developing forms on iOS. Button taps don't remove focus from UITextField / UITextView the same way they would in an HTML form.
I'm sure there are more elegant ways to solve this, but if I want to consistently do this across all forms I ensure that the following line of code is run when users tap on any buttons of mine.
- (void)userDidTapButton:(id)sender
{
[[[UITextField new] becomeFirstResponder] resignFirstResponder]
// the above embarrassing line of code basically creates a new textfield
// puts focus in it (thereby removing focus from any existing textfields
// and then removes focus again
// this ensures that delegate events fire on your existing textfields
// finally, run any other button code
}
I have a problem and I can't find the solution for it. At the moment I have a tap gesture recogniser in my VC's viewDidLoad() that will dismiss the keyboard if a tap is recorder on screen. Problem is that when the user has finished completing the text fields and he presses the "Register Account" button it is still recognised as a tap and only removes the keyboard but the button does not respond to the tap and the selector function is not called.
I want as soon as the button was tapped with the keyboard on screen to call the function and do its business. Please help.
Just posting the first line of the function called by the button because for this question is as far as I have got:
#objc fileprivate func createAccount() {
confirmPasswordTextField.resignFirstResponder()
If you just want to make all buttons actionable (along with the keyboard dismissing) all you have to do is make your tap gesture recognizer not cancel touches in view:
var cancelsTouchesInView: Bool { get set }
So just set:
myTapGesture.cancelsTouchesInView = false
https://developer.apple.com/documentation/uikit/uigesturerecognizer/1624218-cancelstouchesinview
This will make it so that when the user taps on the "Register Account" button the keyboard will dismiss and the action will also be performed.
As you know, split view controller hides the master view and displays detail view in full screen mode in ipad. In the full screen mode, ios creates a bar button for the master view on the navigation bar. My question is, is it possible to reposition that button to the far right instead of left? Because my detail view is embedded inside a navigation view controller and there are severals views associated with it. It gets confusing when master view is hidden and the detail view has button to go back to the previous view.
In above screencap, "Category" is a button to display the masterview and "List of Events" is a back button. If you have better way to handle this situation, please feel free to suggest.
Yes, you can do it just send a NotificationCenter.default to the split view controller and change self.preferredDisplayMode in your splitview and coming to moving the category buttom u either can use the right bar button in navigationbar or create your custom navigation bar.
Hope this helps
For those who are having the same issue, I found a very simple solution. All you need to do is assign the rightBarButtonItems with leftBarButtonItems value and set the leftBarButtonItems to nil. Voila, that's about it.
if let leftButton = self.navigationItem.leftBarButtonItems {
self.navigationItem.rightBarButtonItems = leftButton
self.navigationItem.leftBarButtonItems = nil
}
I have implemented a widget which has a grid (QTableView object) and two scollbars, one horizontal and one vertical. I have implemented a function that fetches the data to be shown in the grid from a database. I want when the user pressed the arrow from the scroll bar in order to make a single step the application instntly fetch the data. On the contrary when the user scrolls with the whell or move the slider the app don’t fetch the data instantly. More specifically i want the data to be fetched when the user stops the slider for some time or releases the slider. For this reason i have used sliderReleased() signal. Moreover, i have write, as a user from this forum suggested, this code for the vertical scrolling actions.
void handleVTableScrollAction(int action)
{
switch(action)
{
case QAbstractSlider::SliderSingleStepAdd:
case QAbstractSlider::SliderSingleStepSub:
drawGrid();
requestSlot();
break;
case QAbstractSlider::SliderMove:
drawGrid();
m_Timer.start(500);
}
the timer is connected to a slot the fetches the data
connect (&m_Timer, SIGNAL(timeout()), this, SLOT (requestSlot()));
So my problem is when i wnt to make a single step (by pressing the arrow key) the app don’t responds instantly. When i press the arrow for the firtst time nothing seems to be done, but when i am pressing second time the grid follows the movement. All the other movements(wheel and slider move) work fine.
So i tried to use the valueChange() signal just like this:
connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(sliderSigleStep()));
connect(ui->verticalScrollBar, SIGNAL(sliderMoved(int)), this, SLOT(sliderMoveSlot()));
In this way the single step works fine, but the sliderMoveSlost is never called as the valueChanged singal is always emmited first.
Is there an explantion for my first issue?
Can i call a function with the condition that two signals emmited? For example call the sliderMoveSlot only if sliderMove(int) and valueChanged(int) singals emmited and call sliderSingleStep() if only valueChanged(int) is emmited.
I'm trying to have a list of Gtk::Widgets that when clicked on I need to highlight the widget, but when the user holds the button down, and drags to another widget, the first one will 'unhighlight' and the new one will highlight on enter_notify.
I've tried using the on_enter_notify_event, and on_button_press_event in multiple combinations ( yes, I'm adding the events ), but every time I 'press' the widget, it starts a drag event, and enter_notify and leave_notify won't fire.
Is there a way to ignore the drag event? I've tried ending it when it starts, but I think the problem is the on_notify won't trigger with the mouse down. Is there another way of doing it?
Any help or suggestions would be greatly appreciated.
Okay, apparently when a widget gets activated or clicked, the GdkDevice 'grab()'s the widget and only sends events to THAT widget. So I've taken the device from the event, and called 'ungrab()' on it so it allows the other cells to receive events. Then on my other cells I check the event->state in the on_enter_notify_event to see if the mouse is down, and voila! The cell is highlighted.
bool cell::on_button_press_event(GdkEventButton* event) {
highlight_cell();
gdk_device_ungrab(event->device, event->time);
return true;
}