我正在尝试在我的 collectionViewCell 中实现 UISwipeGestureRecognizer,因此当您向左滑动时,单元格会消失。我想要实现的(我找不到方法)是为滑动设置动画,因此当我向左滑动单元格时,它会以淡入淡出效果消失。这是我在方法内的代码cellForItemAtindexPath
let cSelector = #selector(reset(sender:))
let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)
UpSwipe.direction = UISwipeGestureRecognizerDirection.left
cell.addGestureRecognizer(UpSwipe)
Run Code Online (Sandbox Code Playgroud)
方法
func reset(sender: UISwipeGestureRecognizer) {
let cell = sender.view as! UICollectionViewCell
let i = self.collectionView?.indexPath(for: cell)!.item
self.messages.remove(at: i!)
self.collectionView?.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
谢谢!!!
编辑: 我想我找到了最简单的方法,但我遇到了一些麻烦。我尝试在单元格中实现 UIPanGestureRecognizer。这就是它的样子......
项目单元格
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(gestureRecognizer:)))
cell.addGestureRecognizer(gestureRecognizer)
Run Code Online (Sandbox Code Playgroud)
方法
func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .began {
// When the drag is first recognized, you can get the starting coordinates here
}
if gestureRecognizer.state …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一些代码,但是我在标题中得到了错误......这里是代码......
let text: NSString = messages[indexPath.row] as! NSString
var size: CGSize = text.boundingRectWithSize(CGSizeMake(240.0, 480.0), options: NSStringDrawingOptions.UsesDeviceMetrics, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14.0)], context: nil)
Run Code Online (Sandbox Code Playgroud)
我在第二行收到错误
另外,我有Objective-C代码,没问题......但是我想在Swift中使用它
NSString *text = [messages objectAtIndex:indexPath.row];
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0f, 480.0f) lineBreakMode:UILineBreakModeWordWrap];
Run Code Online (Sandbox Code Playgroud)
提前致谢!!!