我的场景是,我有一个数组中的图像集合。在 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/