Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS SWIFT-收集查看通过触摸扩展的特定单元格_Ios_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

iOS SWIFT-收集查看通过触摸扩展的特定单元格

iOS SWIFT-收集查看通过触摸扩展的特定单元格,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我有水平流的集合视图,单元格高如屏幕,屏幕宽/4 所以我想添加一些类似动画过渡的东西,这样当你尝试用两个手指展开单元格时,这个单元格将扩展其宽度,直到手指到达设备的侧面,并且当手指移动时,其他一些东西也会被设置动画 那么,我如何跟踪moove的手指,在vc中使用集合视图调用func,并操作组件和单元格的大小呢。同样,在cv中扩大一个特定的单元格宽度,以便其他单元格移动,这对我来说也是一个小技巧 谢谢你的帮助)我很想加上这句话作为评论,但我需要50%的声誉才能做到这一点,所以对反对票要仁慈:p 您

我有水平流的集合视图,单元格高如屏幕,屏幕宽/4

所以我想添加一些类似动画过渡的东西,这样当你尝试用两个手指展开单元格时,这个单元格将扩展其宽度,直到手指到达设备的侧面,并且当手指移动时,其他一些东西也会被设置动画

那么,我如何跟踪moove的手指,在vc中使用集合视图调用func,并操作组件和单元格的大小呢。同样,在cv中扩大一个特定的单元格宽度,以便其他单元格移动,这对我来说也是一个小技巧


谢谢你的帮助)

我很想加上这句话作为评论,但我需要50%的声誉才能做到这一点,所以对反对票要仁慈:p

您需要使用
UIViewControllerAnimatedTransitioning
UIViewControllerTransitioningDelegate
,以及
uipercentdriventeractivetransition

对于ViewController,可以使用UICollectionViewCell的帧进行动画转换,因此对于ViewController.view,必须使用convertRect方法

动画转换应添加NewViewController的屏幕截图,并将convertRect方法的结果作为其开始帧。然后,动画将从NewViewController的开始帧到最后一帧

测试动画并检查其是否具有所需的结果。然后实施 将
UIPercentDrivenInteractiveTransition
连接到
UIPinchgTestureRecognitor
。我建议将挤压手势添加到每个单元格中,然后为单元格创建一个委托,并将
uipercentdriventeractivetransition
设置为实现函数
func userdidusepinchgestrue(手势:uipinchgestruerecognizer)
的委托。在该函数中,您可以计算转换完成的百分比


如果这面文字墙有点吓人,我很抱歉,我希望这能帮助你。如果您尚未实现
UIViewControllerImagedTransitioning
UIViewControllerTransitioningDelegate
UIPercentDrivenInteractiveTransition
,我建议您查看本教程

,您可以使用UIPinchgTestureRecognitor使用两个手指处理缩放。通过读取视图的缩放比例值,可以更改单元的高度和宽度,然后重新加载单元

 UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchWithGestureRecognizer:)];
[cell addGestureRecognizer:pinchGestureRecognizer];
斯威夫特:

var pinchGestureRecognizer: UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: Selector("handlePinchWithGestureRecognizer:"))
cell.addGestureRecognizer(pinchGestureRecognizer)
func handlePinchWithGestureRecognizer(sender: UIPinchGestureRecognizer)
{
    sender.view!.transform = CGAffineTransformScale(sender.view!.transform,
    sender.scale, sender.scale)
} 
读取缩放比例值并在此处写入变换内容:

-(void)handlePinchWithGestureRecognizer:(UIPinchGestureRecognizer *)pinchGestureRecognizer{
    self.cell.transform = CGAffineTransformScale(self.testView.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
}
斯威夫特:

var pinchGestureRecognizer: UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: Selector("handlePinchWithGestureRecognizer:"))
cell.addGestureRecognizer(pinchGestureRecognizer)
func handlePinchWithGestureRecognizer(sender: UIPinchGestureRecognizer)
{
    sender.view!.transform = CGAffineTransformScale(sender.view!.transform,
    sender.scale, sender.scale)
} 

你也可以参考这一点:

尝试这种方法,一切都很好,但唯一缺少的是,虽然尝试手指和手机侧可能会远离ech其他,是否有任何wat来跟踪手指的准确位置,并将其设置为手机侧,以便在所有设备上都更准确?我可以做所有的计算或其他的事情,我只需要一些东西,比如发送者的手指在屏幕上的位置。无论如何,非常感谢你的帮助