Dragging Gestures in iOS 8 Today Extensions

2019-02-03 15:04发布

I'm using a UIView subclass in my Today widget. The view makes use of swiping gestures. However, these gestures either scroll the whole Notification Center up and down, or make the Notification Center switch from Today to Notifications.

Is there any way to prevent the touch events to be bubbled up to the Notification Center scroll view? Using [self setExclusiveTouch:YES]; in the subclass did not solve it unfortunately.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-03 15:47

Apples official advise as mentioned in another answer:

Avoid putting a scroll view inside a widget. It’s difficult for users to scroll within a widget without inadvertently scrolling the Today view.

This is pretty poorly written advice from Apple. It is perfectly fine to use a scroll view in a Today widget but you must disable scrolling so that it doesn't interfere. Apple even use a UITableView in their WWDC talk.

Basically it advises you not to interfere with the Notification Centers existing gestures.
The existing gestures happen to be scrolling in all four directions so you are pretty limited on what you can do with gestures in a widget.

What sort of gesture are you trying to achieve? You mentioned swiping but if you do that you're going to interfere with the existing gestures and break things. This sort of behaviour wouldn't be allowed in a widget as it would effect the UX of the operating system itself.

Maybe you should look into taking a different approach to handle your action?

查看更多
放荡不羁爱自由
3楼-- · 2019-02-03 15:48

According to Apple's App Extensions Programming Guide:

"Avoid putting a scroll view inside a widget. It’s difficult for users to scroll within a widget without inadvertently scrolling the Today view."

查看更多
霸刀☆藐视天下
4楼-- · 2019-02-03 15:49

Is there any way to prevent the touch events to be bubbled up to the Notification Center scroll view? Using [self setExclusiveTouch:YES]; in the subclass did not solve it unfortunately.

No. Because of the remote view hosting that your Today widget is being presented inside, [self setExclusiveTouch:YES] doesn't quite do what you want.

The rough architecture in iOS 8.0 is:

[User touch creates a UITouch]
            |
            v
Notification Center (UIScrollView)
            |
            v
  UIRemoteView container
  (presents your UIView)
[crosses process boundary]
            |
            v
your Today widget's UIView

Think of the touch as basically becoming cloned when it crosses the process boundary. Your view's exclusive touch desires are only relevant in your widget's process space/window, and don't propagate back outwards to the Notification Center which is hosting you remotely.

查看更多
登录 后发表回答