ios - ios中出现UISwipeGestureRecogniser时的UIImageView动画

标签 ios objective-c uiscrollview uiimageview uigesturerecognizer

我的场景是,我有一个数组中的图像集合。在 UIScrollView 中动态创建 UIImageView。代码如下所示。

- (void)createImage
{
    UIImageView *imgFashion;

    CGFloat newHeight = 0.0;
    int xPos = 10;
    int yPosL = 10;
    int yPosR = 10;

    btnScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 83, 320, 485)];

    for (int i=0; i<[buttonImageArr count];i++)
    {

        UIImage *img = [buttonImageArr objectAtIndex:i];
        originalImageWidth = img.size.width;
        originalImageHeight = img.size.height;

        newHeight = originalImageHeight * (150/originalImageWidth);
        if (xPos == 10)
        {

            imgFashion=[[UIImageView alloc]initWithFrame:CGRectMake(xPos, yPosL, 150, newHeight)];
            xPos = 160;
            yPosL = yPosL + newHeight;

        }
        else
        {
            imgFashion=[[UIImageView alloc]initWithFrame:CGRectMake(xPos, yPosR, 150, newHeight)];
            imgFashion.tag=i;
            xPos = 10;
            yPosR +=newHeight;
        }
        imgFashion.tag=i;
        imgFashion.image = [buttonImageArr objectAtIndex:i];
        imgFashion.userInteractionEnabled = YES;
        [btnScroller addSubview:imgFashion];
        imgFashion.layer.borderWidth = 3.0;
        imgFashion.layer.borderColor = [UIColor whiteColor].CGColor;
        UISwipeGestureRecognizer *profile_SwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes_profile:)];

        profile_SwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        profile_SwipeGestureRecognizer.numberOfTouchesRequired = 1;
        profile_SwipeGestureRecognizer.enabled = YES;
        [imgFashion addGestureRecognizer:profile_SwipeGestureRecognizer];
        btnScroller.scrollEnabled=YES;
    }

    btnScroller.contentSize=CGSizeMake(xPos, yPosR+newHeight);
    [self.view addSubview:btnScroller];

}

现在我将滑动任何图像的顶部,我想从 View 中删除该图像。我为此功能编写了代码。

- (void)handleSwipes_profile:(UISwipeGestureRecognizer *)paramSender
{
    if (paramSender.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        [paramSender.view removeFromSuperview];
        selectedBtn = paramSender.view.tag;
        [buttonImageArr removeObjectAtIndex:selectedBtn];
        [btnScroller removeFromSuperview];
        btnScroller = nil;
        [self createImage];
        [self.view setNeedsDisplay];
    }
}

我的问题是,我想在从 View 中移除之前旋转图像。

最佳答案

您可以使用 UIView 的动画方法以及 UIViewAnimationOptionCurveLinear 和重复计数等选项实现此目的,如下所示

- (void)handleSwipes_profile:(UISwipeGestureRecognizer *)paramSender
{
    if (paramSender.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        [UIView animateWithDuration: 0.2f
                              delay: 0.0f
                            options: UIViewAnimationOptionCurveLinear
                         animations: ^{
                             [UIView setAnimationRepeatCount:3];
                             paramSender.view.transform = CGAffineTransformRotate(UserNameField.transform, M_PI );
                         }
                         completion: ^(BOOL finished) {
                             NSLog(@"finished");
                             if (finished) {
                                 [paramSender.view removeFromSuperview];
                                 selectedBtn = paramSender.view.tag;
                                 [buttonImageArr removeObjectAtIndex:selectedBtn];
                                 [btnScroller removeFromSuperview];
                                 btnScroller = nil;
                                 [self createImage];
                                 [self.view setNeedsDisplay];

                             }
                         }];
    }


}

如果您需要更多选项,请查看此问题 UIView Infinite 360 degree rotation animation?

关于ios - ios中出现UISwipeGestureRecogniser时的UIImageView动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23929734/

相关文章:

iphone - 程序收到信号 EXC_BAD_ACCESS : Simple Navigation

ios - 旋转后保持 subview 相对位置

ios - iOS 上使用 Memory Monitor 时虚拟内存消耗和实际内存的区别

ios - UIBarButtonItem 背景图片和设置 Action

ios - 水平拾色器的 UI 帮助

iphone - UIScrollView 和 setContentOffset

ios - float 在 UIView 上的水平 ScrollView 而不是 Paging

ios - 在 Xcode 9/iOS 11 中将应用程序图标自定义为构建阶段

ios - RxSwift 观察数组中struct类型的变量字段

c++ - "symbol(s) not found for architecture x86_64"由于 C 函数而导致的错误