Issues with iOS 7 and scrolling through a UIScrollView that contains UIButtons

谁说胖子不能爱 提交于 2019-12-11 09:19:17

问题


I've been tasked with updating an app we have that I didn't write. It contains a scrollview that scrolls horizontally and only contains UIButtons. The buttons not only have an action to open the app they represent, but they can be dragged if tapped and held. There is another scrollview below the scrollview in question that accepts the dragging of the buttons.

Everything has and is working as expected pre iOS 7. On an iOS 7 device, the button taps are being registered as soon as the scrollview is touched. The button will show a lit state like it was selected and the scrollview will begin scrolling. On a pre iOS 7 device, the scrollview will begin to scroll instead of registering the tap.

Anyone experience any issues with UIScrollView with iOS7? setDelaysContentTouches: is set to YES, which should prevent this from happening. I'm at a loss.


回答1:


I experienced the same issue. I was sticking a number of buttons into a UIScrollView that was to be horizontally scrolled. Then I was laying out these buttons using Auto Layout. Try as I might, using a combination of -setDelaysContentTouches:YES and -setExclusiveTouch:YES, even trying -setUserInteractionEnabled:NO on the buttons, nothing worked. The scroll view wouldn't scroll, only the buttons got touch events.

What turned out to be the problem was the use of Auto Layout. I'm not entirely sure why, but after disabling that and laying the buttons out using springs-n-structs, the scroll view worked as intended. The scroll view would scroll, and the buttons received touches if I just tapped.

So maybe try not using Auto Layout on the buttons?




回答2:


One of the big problem issues was that the buttons could also be draggable. They could be dragged around and reordered in their own scrollview, or moved to another scrollview. What we ended up doing was subclassing our buttons being used in the scrollviews. The subclass kept track of who the original button owner was and overrode touchesBegan: , touchesMoved: , and touchesCancelled:.

When touches were recognized by our button subclass, it would determine if the button was being dragged and call the appropriate method. We then would call super on our touch methods first, and then on [self nextResponder].

It is company code, so I can't directly post it without asking. If I get the okay, I'll update my answer with the actual code.



来源:https://stackoverflow.com/questions/22472201/issues-with-ios-7-and-scrolling-through-a-uiscrollview-that-contains-uibuttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!