在摆动图像上显示删除按钮并删除该特定图像

时间:2012-11-27 09:27:02

标签: iphone xcode uiscrollview uianimation

我在滚动视图中添加了图片。长期以来,我已经为所有图像提供了摆动动画。 我想在我们卸载任何类似的应用程序时,在iphone的右上角显示删除按钮。

- (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");
}

这里没有调用选择器....我该怎么解决这个问题.. ???

3 个答案:

答案 0 :(得分:1)

您可以在最初的所有自定义视图中添加带有TAG值的删除按钮,并将其隐藏起来。现在使用- (void)startWobble方法,只需使用TAG即可取消隐藏。

我已经以这种方式在我的一个应用程序中完成了。希望这会对你有所帮助。

答案 1 :(得分:1)

简单.....

#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;
     }
}

来自thisQuestion

答案 2 :(得分:0)

从苹果文档中找到这句话,并记住了你的问题:

  

在动画期间,暂时禁用用户交互   动画的视图。 (在iOS 5之前,用户交互是   对整个应用程序禁用。)