Reputation: 1208
My Scenario is, i have collection of images in an array. dynamically creating UIImageView in a UIScrollView. code is shown below.
- (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];
}
Now i will swipe top of any images, i want to remove that image from view. i write the code for this functionality.
- (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];
}
}
My Question is, i want to rotate the image before remove from view.
Upvotes: 1
Views: 105
Reputation: 10739
You can use the ´- animationWithDuration´ method like this
[UIView animateWithDuration:1.0 animations:^{
// perform your rotation here
[_yourImageView setTransform:CGAffineTransformMakeRotation(180)];
} completion:^(BOOL finished) {
[paramSender.view removeFromSuperview];
selectedBtn = paramSender.view.tag;
[buttonImageArr removeObjectAtIndex:selectedBtn];
[btnScroller removeFromSuperview];
btnScroller = nil;
[self createImage];
[self.view setNeedsDisplay];
}];
Upvotes: 1
Reputation: 2330
You can achieve this using the animation methods of UIView with options like UIViewAnimationOptionCurveLinear and repeat count like below
- (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];
}
}];
}
}
If you need more options have a look at this question UIView Infinite 360 degree rotation animation?
Upvotes: 1