結構 的UIViewController - UIScrollView中 - 的UIButtoniphone - 如何滾動由UIButton的感動事件UIScrollView的滾動型
我要做出滾動視圖可以接收按鈕事件。所以每當用戶在按鈕上滾動(拖動),滾動視圖就會自動滾動。
我做了按鈕來與事件轉發像下面
- (IBAction)buttonTouchedMove:(id)sender withEvent:(UIEvent *)event {
[[sender nextResponder] touchesMoved:[event allTouches] withEvent:event];
}
- (IBAction)buttonTouchedDown:(id)sender withEvent:(UIEvent *)event {
[[sender nextResponder] touchesBegan:[event allTouches] withEvent:event];
}
和觸摸改變移動滾動型移動處理,我做了下面的代碼
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.oldPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint offset = self.scrollView1.contentOffset;
UITouch *touch = [touches anyObject];
self.newPoint = [touch locationInView:self.view];
int diffX = newPoint.x - oldPoint.x;
offset.x = offset.x - diffX;
[scrollView1 setContentOffset:offset animated:YES];
self.oldPoint = self.newPoint;
}
但是,滾動型反應奇怪..不移動,因爲我觸摸移動。
嘗試類似這樣的事情int diffX = 10 *(newPoint.x - oldPoint.x);這是因爲我thnk你的按鈕框架小於視圖的 – Saad
謝謝,它的工作原理。但是,當我拖動它時,scrollview會發抖.. – ytkang
檢查您是否在其他地方設置了內容偏移量 – Saad