简体   繁体   English

如何从多个视图中取消选择视图使用手势识别器快速选择一个视图?

[英]How to deselect View from multiple view When Select new one using gesture recognizer in swift?

How to select a view from multiple view and previous selected will be deselect using TapgestureRecognizer ? 如何从多个视图中选择一个视图,而先前选择的视图将使用TapgestureRecognizer取消选择?

@objc func tapGestureHandler(gesture: UITapGestureRecognizer){
    if drawView.isUserInteractionEnabled == true{
        return
    }
    if gesture.state == UIGestureRecognizer.State.ended{
        if let embedTextView = gesture.view as? EmbedTextView {
            textMode()
            self.textTools.editingTarget = embedTextView
        }
    }
    self.stampFrame.borderWidth = 1
    self.stampFrame.borderColor = UIColor.black


}

要在集合视图中取消选择:-

collectionView.deselectItem(at: indexPath, animated: false)

// Get index from tap gesture , for did deselect //从点击手势获取索引,取消选择

@objc func tapBlurButton(_ sender: UILongPressGestureRecognizer) {

        let location = sender.location(in: collectionView) // point of touch in collectionView
        if let indexPath = collectionView.indexPathForItem(at: location) { // indexPath of touch location
            let indexPaths = IndexPath(item: indexPath , section: 0)
            collectionView.selectItem(at: indexPaths, animated: true, scrollPosition: .top)
            collectionView.delegate?.collectionView!(collectionView, didDeselectItemAt: indexPaths)
    }
}

// Hope it works for you! // 希望这对你有用! thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将手势识别器从一个视图传递到另一个视图 - How can I pass a gesture recognizer from one view to another 如何将 Pan Gesture Recognizer 从一个视图转移到另一个视图? - How to transfer Pan Gesture Recognizer from one view to other? 在一个视图上的多手势识别器 - Multi gesture recognizer on one view iOS-对视图中的多个Tableview或CollectionView使用/传递手势识别器(Swift) - iOS - Use/pass gesture recognizer for multiple Tableviews or Collectionviews in a View(Swift) 如何在父视图中使用手势识别器将触摸传递到子视图 - how to pass touches to subview with gesture recognizer in parent view swift 使用手势识别器(LongPress)从“地图视图”中获取GPS坐标 - Get GPS Coordinates from Map View using Gesture Recognizer (LongPress) 圆形视图上的手势识别器 - Gesture recognizer on a circular view 使用点击手势识别器禁用提示视图 - Using tap gesture recognizer to disable a tip view Swift 父视图上的手势识别器而不影响子视图 - Swift Gesture Recognizer on parent View without affecting the child View 迅捷:当我打开视图控制器并第一次按下手势识别器时,它说我按下了两次。 如何解决这个问题? - swift: when I open the view controller and press the gesture recognizer for the first time it says that i pressed it twice. how to fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM