4

I have added images in scroll view. On long press i have given wobble animation to all images. i want to show delete button on the right top corner of every image as in iphone when we uninstall any application same like that.

- (void)startWobble {
for (UIView *imgView in viewsInScrollView) {
    UIButton *deleteImgButton = [[UIButton alloc] initWithFrame:CGRectMake(55,-7,12,12)];        
    [deleteImgButton setImage:[UIImage imageNamed:@"close_icon.png"] forState:UIControlStateNormal];
    [deleteImgButton addTarget:self action:@selector(deleteImage:) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:deleteImgButton];


    imgView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5));        
    [UIView animateWithDuration:0.20
                          delay:0.0
                        options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse)
                     animations:^ {
                         imgView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5));
                     }
                     completion:NULL
     ];
}
}
-(void)deleteImage : (id)sender {
     NSLog(@"Delete Image");
}

here the selector is not called.... how do i solve this..???

Pallavi
  • 249
  • 2
  • 10
  • Can you show the header of this file ? Did you declare deleteImage method in your header file ? – giorashc Nov 27 '12 at 09:32
  • when i added animation to imageview and added button in image view may be it disables user interaction http://stackoverflow.com/questions/12354919/add-selector-to-button-on-uiscrollview-views-added-dynamically – Pallavi Nov 27 '12 at 09:39
  • I want to add action on that delete image button..... but 'deleteImage' method is not getting call.... – Pallavi Nov 27 '12 at 10:32

3 Answers3

1

You can add the delete button with a TAG value in all of your custom views initially and make them hidden. Now in - (void)startWobble method you can just make them unhide just using their TAG.

I have done in one of my applications in this way . Hope this will help you.

Mihir Das
  • 458
  • 4
  • 13
  • views are not custom, i added it dynamically, user can add or delete image dynamically.. – Pallavi Nov 27 '12 at 10:38
  • Yes the code you have written to add the delete button in - (void)startWobble . You can use this code where you are creating those views dynamically. Thats what i mean.. – Mihir Das Nov 27 '12 at 10:40
  • yes i tried but it is not calling that selector, i thin k it is because of '[imgView addSubview:deleteImgButton];' i added that in image view and animate that image view. during animating it not calls any selector. i try to add that in scroll view, at that time it works fine :) – Pallavi Nov 27 '12 at 11:00
  • You have added that to image view ?? Thats why that is not calling .You are right. Create a View add imageview and the delete button that view . This way you can fix your issue.. – Mihir Das Nov 27 '12 at 11:05
1

Simple.....

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5.0));

itemView.transform = leftWobble;  // starting point

[UIView beginAnimations:@"wobble" context:itemView];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:10];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];

itemView.transform = rightWobble; // end here & auto-reverse

[UIView commitAnimations];

...

- (void) wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{
     if ([finished boolValue]) {
        UIView* item = (UIView *)context;
        item.transform = CGAffineTransformIdentity;
     }
}

Got it from thisQuestion

Community
  • 1
  • 1
Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76
0

Found this quote from apple docs and remembered your question :

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)

giorashc
  • 13,691
  • 3
  • 35
  • 71