如何在 UIView Like Swipeable TableView Cell 中制作类似于“滑动解锁”的动画

Posted

技术标签:

【中文标题】如何在 UIView Like Swipeable TableView Cell 中制作类似于“滑动解锁”的动画【英文标题】:How to make an animation similar to "Slide to unlock" within a UIView Like Swipable TabbleView Cell 【发布时间】:2015-07-08 07:02:47 【问题描述】:

在我的 Xib 中。我已经包含了 3 个子视图和 3 个小图像视图

![我必须为每个视图分别包含向右滑动和向左滑动的动画。根据项目被收藏的滑动方向,一个视图的简单滑动可以正常工作,并且图像位置也可以改变][2]

 //........towards right Gesture recogniser for swiping.....//
    UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
    rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [rightRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:rightRecognizer];

    //........towards left Gesture recogniser for swiping.....//
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [leftRecognizer setNumberOfTouchesRequired:1];
    [self.view addGestureRecognizer:leftRecognizer];

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer


    NSLog(@"Right Gesture");
    self.Favimage.hidden = false;
    self.closeImage.hidden = true;




- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer


    NSLog(@"Left Gesture");
    self.Favimage.hidden = true;
    self.closeImage.hidden = false;



这是我现在尝试的。我必须用更好的动画来做到这一点。提前致谢

【问题讨论】:

使用UISlider 它有你需要的一切。 @cy-4AH 抱歉,我不这么认为。当我向右或向左滑动时,我必须对视图进行动画处理。如果我向右滑动。关闭标志被隐藏,最喜欢的东西变得可见,最后只有一只鞋和一个刻度线鞋可见。你有任何想法来实现这个谢谢你的回复 【参考方案1】:

我认为。这就是你要找的东西

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer


    NSLog(@"Right Gesture");
    self.closeImage.hidden = true;
   // self.shoe.hidden = true;
    //Do moving

    CGRect finalFrame = CGRectMake(150,5, 64, 63);
    [UIView animateWithDuration:0.5 animations:^
        _shoe.frame = finalFrame;
         self.Favimage.hidden = true;
     completion:^(BOOL finished) 
        self.Favimage.hidden = false;

      // [_Favimage removeFromSuperview];

        //[_Favimage removeFromSuperview];
        //[self.view removeGestureRecognizer:gestureRecognizer];
    ];


- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer


    NSLog(@"Left Gesture");
    self.Favimage.hidden = true;
    self.closeImage.hidden = false;

    CGRect finalFrame = CGRectMake(77,5, 70, 63);

    [UIView animateWithDuration:0.5 animations:^
        _shoe.frame = finalFrame;

     completion:^(BOOL finished) 
        //self.Favimage.hidden = false;

        //[_Favimage removeFromSuperview];

        //[_Favimage removeFromSuperview];
        //[self.view removeGestureRecognizer:gestureRecognizer];
    ];
    // do moving

试试这个

【讨论】:

以上是关于如何在 UIView Like Swipeable TableView Cell 中制作类似于“滑动解锁”的动画的主要内容,如果未能解决你的问题,请参考以下文章

如何在 React Native 中动态创建多个 Refs

React Native Swipeable 最小激活距离

react-swipeable-views轮播图实现下方的切换点控制组件

React Native Swipeable(滑动删除)未关闭

类似于 iOS 7 Safari 的 UIActionSheet-like 控件

对 uicontrol 的 nextresponder 感到困惑