在Scroll View上翻頁(Paging)似乎只能根據Scroll View這個元件的大小來決定,然而今日我有需求來改變其翻頁的大小,該如何做呢?
有神人這麼建議⋯⋯
- turn off
clipsToBounds - put a
UIViewover the scrollview, wherever you want the user to be able to touch - move the
panGestureRecognizerto that view[touchableView addGestureRecognizer:_scrollView.panGestureRecognizer];
如果只是縮小Scroll View,且讓其上的元件不被切掉(第一點),那麼觸控範圍只有在被縮小Scroll View上頭,這樣不太合理,那麼我們就希望讓兩邊空白處也能觸控Scroll View。神人建議可以將panGestureRecognizer轉移共用,在Scroll View底下鋪View,將Scroll View的panGestureRecognizer設定到View上頭,這樣就大功告成!
神人說這麼做,Apple是允許的,在WWDC的Session (WWDC Session 223, “Enhancing User Experience with Scroll Views)上有提到,Scroll View有兩個gesture recognizer,就是因為大家的期望而設計出來的,如此就能在非該Scroll View上的元件來移動和縮放該Scroll View囉~
// Use these accessors to configure the scroll view’s built-in gesture recognizers.
// Do not change the gestures’ delegates or override the getters for these properties.
@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);
// `pinchGestureRecognizer` will return nil when zooming is disabled.
@property(nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);


隨意留個言吧:)~