[英]GestureRecognizer is not working for Tableview Dropdown dismiss
[英]How to dismiss programmatically the clipsToBounds property when a GestureRecognizer begin?
我有一個UIScrollView
,它可以包含許多視圖。 為了實現良好的滾動(滾動時內容不會超出視圖之外),請在Main.sotryboard
上單擊UIScrollView
,然后在屬性檢查器中允許Clip Subviews
屬性:
我的問題: UIScrollViews
中的所有視圖都是可拖動的(因為它們都具有UIPanGestureRecognizer
。因此,當我嘗試將其拖動到UIScrollView
,它們只是消失了。 實際上,它們只是在其他所有視圖之后
舉個例子,我還有其他一些組件,它們允許從先前的UIScrollView
刪除視圖。 因此,當我開始從中拖放時,它消失了,然后重新出現在放置了該視圖的第二個組件中。
我嘗試過的事情:我有一個特殊的UIPanGestureRecognizer
用於UIPanGestureRecognizer
來自此UIScrollView
的視圖。 所以,我實際上有這個(顯然,它不起作用,否則我不會在這里):
//Here recognizer is the `UIPanGestureRecognizer`
//selectpostit is the name of the view I want to drag
if(recognizer.state == UIGestureRecognizerStateBegan){
selectpostit.clipsToBounds = NO;
}
關於如何改善這一點的任何想法? 提前致謝。
您可以嘗試在每次手勢開始時將scrollView.clipsToBounds重置為NO,但這會導致副作用,當在拖動過程中滾動視圖之外的其他內容變為可見時。
我建議平移開始時為可拖動視圖拍攝快照,將其放置在滾動視圖的父級上,然后將其移動。 這種方法應該可以解決您的問題。
這是代碼:
- (void)onPanGesture:(UIPanGestureRecognizer*)panRecognizer
{
if(panRecognizer.state == UIGestureRecognizerStateBegan)
{
//when gesture recognizer starts, making snapshot of the draggableView and hiding it
//will move shapshot that's placed on the parent of the scroll view
//that helps to prevent cutting by the scroll view bounds
self.draggableViewSnapshot = [self.draggableView snapshotViewAfterScreenUpdates: NO];
self.draggableView.hidden = YES;
[self.scrollView.superview addSubview: self.draggableViewSnapshot];
}
//your code that updates position of the draggable view
//updating snapshot center, by converting coordinates from draggable view
CGPoint snapshotCenter = [self.draggableView.superview convertPoint:self.draggableView.center toView: self.scrollView.superview];
self.draggableViewSnapshot.center = snapshotCenter;
if(panRecognizer.state == UIGestureRecognizerStateEnded ||
panRecognizer.state == UIGestureRecognizerStateCancelled ||
panRecognizer.state == UIGestureRecognizerStateFailed)
{
//when gesture is over, cleaning up the snapshot
//and showing draggable view back
[self.draggableViewSnapshot removeFromSuperview];
self.draggableViewSnapshot = nil;
self.draggableView.hidden = NO;
}
}
我建議您通過ray wenderlich 的長按手勢移動表格視圖單元格來閱讀本文
它說明了如何創建快照
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.