2013-07-23 4 views
0

Я пытаюсь реализовать, долгое нажатие и удаление функциональности 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]; 
    } 
}]; 
} 

ответ

0

Использование в параметре параметров вашей анимации UIViewAnimationOptionAllowUserInteraction

+0

, если я хочу, чтобы остановить анимацию при нажатии кнопки, что я должен делать? – erdemgc

+0

http://stackoverflow.com/questions/554997/cancel-a-uiview-animation –

Смежные вопросы