动画开始时删除功能不起作用?

时间:2013-07-23 11:24:19

标签: ios objective-c uiview uiviewanimation touch-event

我正在尝试实施,长按和删除apple,我自己的功能。

我几乎已经实现,但有一些我无法弄清楚的事情。

当摇动动画时,删除按钮不会触及。

在摇动删除视图时如何处理。

这是我的代码;

    self.frame = CGRectMake(0, 0, 1024, 768);

    [self setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]];


    circleView = [[UIView alloc] initWithFrame:CGRectMake(50,55,90,90)];
    circleView.layer.cornerRadius = 45;

    circleView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
    circleView.layer.borderColor = [[UIColor blackColor] CGColor];
    circleView.layer.borderWidth = 4;

    UILabel* circleIndex = [[UILabel alloc] init];
    circleIndex.frame    = CGRectMake(30, 25, 40, 40);
    [circleIndex setFont:[UIFont fontWithName:@"Arial-BoldMT" size:40]];
    [circleIndex setText:@"A"];

    [circleView addSubview:circleIndex];



    UIView *exitView = [[UIView alloc] initWithFrame:CGRectMake(78,5,20,20)];
    exitView.layer.cornerRadius = 10;

    exitView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:1];
    exitView.layer.borderColor = [[UIColor whiteColor] CGColor];
    exitView.layer.borderWidth = 2;

    UILabel* exitLabel = [[UILabel alloc] init];
    exitLabel.frame    = CGRectMake(5, 0.5, 25, 20);
    [exitLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:25]];
    [exitLabel setTextColor:[UIColor whiteColor]];
    [exitLabel setBackgroundColor:[UIColor clearColor]];
    [exitLabel setText:@"-"];

    [exitView addSubview:exitLabel];


    [circleView addSubview:exitView];

    UIView *alertView  = [[UIView alloc]initWithFrame:CGRectMake(40, 80, 944, 600)];        

    [exitView setUserInteractionEnabled:YES];


    UILongPressGestureRecognizer *longPress =
    [[UILongPressGestureRecognizer alloc] initWithTarget:self
                                                  action:@selector(handleLongPress:)];
    [circleView addGestureRecognizer:longPress];


    UITapGestureRecognizer *singlePress =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                                  action:@selector(handleSinglePress:)];
    [exitView addGestureRecognizer:singlePress];
    //[longPress release];

    [circleView bringSubviewToFront:exitView];

    [alertView addSubview:circleView];

    [self addSubview:alertView];

}
return self;
}




//The event handling method
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer{
//CGPoint location = [recognizer locationInView:[recognizer.view superview]];
if ( recognizer.state == UIGestureRecognizerStateEnded ) {

    //[circleView removeFromSuperview];

    [self shakeView:recognizer.view];
}


 }

- (void)handleSinglePress:(UITapGestureRecognizer *)recognizer{
//CGPoint location = [recognizer locationInView:[recognizer.view superview]];
if ( recognizer.state == UIGestureRecognizerStateEnded ) {

    [recognizer.view.superview removeFromSuperview];

    }


 }

  - (void)shakeView:(UIView *)viewToShake
  {
CGFloat t = 2.0;
CGAffineTransform translateRight  = CGAffineTransformTranslate(CGAffineTransformIdentity, t, 0.0);
CGAffineTransform translateLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, 0.0);

viewToShake.transform = translateLeft;

[UIView animateWithDuration:0.07 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
    [UIView setAnimationRepeatCount:200.0];
    viewToShake.transform = translateRight;
} completion:^(BOOL finished) {
    if (finished) {
        [UIView animateWithDuration:0.05 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
            viewToShake.transform = CGAffineTransformIdentity;
        } completion:NULL];
    }
}];
}

1 个答案:

答案 0 :(得分:0)

在动画UIViewAnimationOptionAllowUserInteraction

的options参数中使用