|
I have just discovered .onLongPressGesture in this proyect I am trying to use .onLongPressGesture with an image that is inside a navigationLink. But if I add .onLongPressGesture to the image, the navigationLink doesn't work anymore... am I doing something wrong? if I add the .onLongPressGesture to the image, The navigationLink clicking on the image doesn't work. if I delete the .onLongPressGesture, it works perfect.
|
|
Are you sure that your code is not working? I recreated your code (below) and both tapping and longPressGesture are working.
|
|
It is not working for me... If I click on the image, it does nothing... I must click on the text to go to th navigationLink... |
SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Hi Kitty, Could my suggestion with simultaneousGesture work in your case?
|
|
OOOOOHHHHHHH !!!! Thanks a lot !!!!! It works perfeeeeect !!!!! Just three more questions... 1.- trying to find an answer to my problem using google I found a modifier called .contextMenu I have seen that it is explained in the course, but I haven't arrived to that part yet... I tried it and it works perfect !!!! except when I add a systemImage... it doesn't show it... Am I doing something wrong? or maybe it is because the contextmenu belongs to an image and that can finish with problems ????
2.- what is the difference between them ? which option is better in my code ? when is better to use .contextMenu and when .onLongPressGesture ???? 3.- The first time I run the app in my iphone, it takes a lot of time to show the options when I click and hold on an image of a book. The next times it works perfect. Can I do something to fix it? Sorry for my English... I am trying to do my best when writing here... |
|
Hi Kitty, Glad you show appreciation! 🤩 I hope to be able to help you further with your completed questions: 1.1 Do you know that many developers get stuck clicking multiple buttons in a list row? (I just want to double check so you have a handle on it.) Text from Paul's article Adding a custom star rating component: "Chances are you'll see things don't quite work right: no matter which star rating you press, it will select 5 stars! I've seen this problem hit countless hundreds of people, no matter how much experience they have. The problem is that when we have rows inside a form or a list, SwiftUI likes to assume the rows themselves are tappable. This makes selection easier for users, because they can tap anywhere in a row to trigger the button inside it. In our case we have multiple buttons, so SwiftUI is tapping them all in order – rating gets set to 1, then 2, then 3, 4, and 5, which is why it ends up at 5 no matter what. We can disable the whole "tap the row to trigger its buttons" behavior with an extra modifier attached to the whole HStack: .buttonStyle(.plain) That makes SwiftUI treat each button individually, so everything works as planned. And the result is much nicer to use: there's no need to tap into a detail view with a picker here, because star ratings are more natural and more common." 1.2 Your code works when I test it. 🤔 Attaching your code without Menu:
"I have a few tips for you when working with context menus, to help ensure you give your users the best experience: If you’re going to use them, use them in lots of places – it can be frustrating to press and hold on something only to find nothing happens. Keep your list of options as short as you can – aim for three or less. Don’t repeat options the user can already see elsewhere in your UI. Remember, context menus are by their nature hidden, so please think twice before hiding important actions in a context menu."
Please report back when you have tried my suggestions. ☺️ |
|
Bout point 2... "If you’re going to use them, use them in lots of places – it can be frustrating to press and hold on something only to find nothing happens. Keep your list of options as short as you can – aim for three or less. Don’t repeat options the user can already see elsewhere in your UI. Remember, context menus are by their nature hidden, so please think twice before hiding important actions in a context menu." so for example if I have a list with a lot of books and a view for each book... is not better adding all the options in both views??? I mean, being able to delete a book, to change the reading status... is not better for the user to have those options in both views ???? Acording to Paul, it is better not to repeat the options, but for example, if I just add the delete option to the book view (and not to the list view), the user must click on the book to delete it, but cannot delete it from the list view... would't it be better to have all those options in as many places as I can to let the users choose the options everywhere? But that is not what Paul is saying... |
|
About point 2... "If you’re going to use them, use them in lots of places – it can be frustrating to press and hold on something only to find nothing happens. Keep your list of options as short as you can – aim for three or less. Don’t repeat options the user can already see elsewhere in your UI. Remember, context menus are by their nature hidden, so please think twice before hiding important actions in a context menu." so for example if I have a list with a lot of books and a view for each book... is not better adding all the options in both views??? I mean, being able to delete a book, to change the reading status... is not better for the user to have those options in both views ???? Acording to Paul, it is better not to repeat the options, but for example, if I just add the delete option to the book view (and not to the list view), the user must click on the book to delete it, but cannot delete it from the list view... would't it be better to have all those options in as many places as I can to let the users choose the options everywhere? But that is not what Paul is saying... Wouldn't be better for the user to have all the options in as many places as posibble in the app? |
|
Hi Kitty, When it comes to deleting things from a list, the default is to use Swipe to delete. In the detail view you can usually find delete in the menu. Please take a look at how the Notes app works. I think that you want as clean and stylish a design as possible, while sticking to the existing design standard. It is nice that there is a good standard and guidelines, see Human Interface Guidelines. |
|
Thaaaaaanks MartinAtElitappar Yes! that is the way I am doing it...!!!! When I want to delete from a list, I am using .ondelete(perform:) to delete by swiping My new problem comes when trying to delete a book from a grip view using an alert... sure it's a silly question... but I am stuck ... How must I call the delete function in my alert if I have let books = [Book] ????
|
|
Hi Kitty, Great! It sounds like you’re making excellent progress with your project – wonderful! 🎉 I noticed you have several follow-up questions. Could you please mark this thread as solved and create a new question? This way, we give others the opportunity to contribute solutions, and it will also make it easier for those seeking answers to find the information they need. Thank you and good luck! 🙏🤩 |
SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.