4

我在滚动视图中添加了图像。在长按时,我为所有图像提供了摆动动画。当我们卸载任何类似的应用程序时,我想在每个图像的右上角显示删除按钮,就像在 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");
}

这里没有调用选择器....我该如何解决这个..???

4

3 回答 3

1

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

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

于 2012-11-27T10:32:58.860 回答
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得到它

于 2013-03-04T14:02:01.767 回答
0

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

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

于 2012-11-27T12:03:25.043 回答