-1

Dans ios 7.0 Je veux juste fermer cette feuille d'action chaque fois que l'utilisateur appuie en dehors de cette popover.I je montre que la feuille d'action sur le bouton clic et en utilisant ce code en essayant d'obtenir un geste du robinet sur actionsheet.windowFiche d'action ne reçoit pas rejeté en cliquant en dehors du pop-up

-(IBAction)buttonClicked:(id)sender{ 
    NSLog(@"button clicked"); 
    NSLog(@"action sheet "); 
    actionSheet = [[UIActionSheet alloc] initWithTitle:nil               delegate:self 
                cancelButtonTitle:nil 
               destructiveButtonTitle:nil 
                otherButtonTitles:@"Rename",@"Delete",@"Cancel" ,nil]; 


    for (UIView *subview in actionSheet.subviews) { 
     if ([subview isKindOfClass:[UIButton class]]) { 
      UIButton *button = (UIButton *)subview; 
      [button setBackgroundColor:[UIColor whiteColor]]; 
      [button setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted]; 

      [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; 
      [button setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected]; 
     } 
    } 
    // [actionSheet setBackgroundColor:[UIColor whiteColor]]; 
    [actionSheet showInView:self.view]; 


    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)]; 
    tap.cancelsTouchesInView = NO; 
    [actionSheet.window addGestureRecognizer:tap]; 

    [actionSheet.window addGestureRecognizer:tap]; 

} 

-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer { 
    NSLog(@"in tap out"); 
    CGPoint p = [gestureRecognizer locationInView:actionSheet]; 
    if (p.y < 0) { 
     NSLog(@" p.y < 0 "); 
    } 
} 

Mais ne reçois pas ce robinet gesture.Please me aider à résoudre ce.

Répondre

0

Ce code vous aide à rejeter la feuille d'action

[self dismissWithClickedButtonIndex:0 animated:YES]; 

Index Bouton '0' est annuler l'index de bouton de bouton.

+0

Je veux fermer la feuille lorsque l'utilisateur touche partout en dehors de la actionsheet pas cliquez sur le bouton – Snigdha

+0

Oui, cela va faire l'utilisation trick ce code dans votre fonction tapout. – Rajjjjjj

+0

Lorsque je tape sur l'écran que la fonction de tapout ne se fait pas appeler.C'est le problème exact – Snigdha

0

Vous pouvez essayer d'ajouter une tapgesture sur différents puis actionSheet.window.

S'il vous plaît essayer d'ajouter tapgesture sur self.superView

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)]; 
tap.cancelsTouchesInView = NO; 
[self.superview addGestureRecognizer:tap]; 
//OR 
[actionSheet.superview addGestureRecognizer:tap]; 

Comme cela, vous pouvez essayer d'autres choses en fonction de vue hiérarque.

Update 1

Essayez de sous-classe la Actionsheet et définir tapgesture en classe elle-même comme.

-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer { 
    CGPoint p = [gestureRecognizer locationInView:self]; 
    if (p.y < 0) { // They tapped outside 
     [self dismissWithClickedButtonIndex:0 animated:YES]; 
    } 
} 

-(void) showInView:(UITabBar *)view { 
    [super showFromTabBar:view]; 

    // Capture taps outside the bounds of this alert view 
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)]; 
    tap.cancelsTouchesInView = NO; // So that legit taps on the table bubble up to the tableview 
    [self.superview addGestureRecognizer:tap]; 
} 

Profitez du codage !!

+0

Oui j'ai même essayé que .. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: action de soi: @selector (tapOut :)]; tap.cancelsTouchesInView = NO; tap.numberOfTapsRequired = 1; actionSheet.superview.userInteractionEnabled = YES; [actionSheet.superview addGestureRecognizer: tap]; mais ne pas entrer dans cette méthode – Snigdha

0

Ce qui suit s'applique à une sous-classe d'une UIActionSheet

actionSheet = [[UIActionSheet alloc] initWithTitle:nil               delegate:self 
           cancelButtonTitle:@"Cancel" 
          destructiveButtonTitle:nil 
           otherButtonTitles:@"Rename",@"Delete" ,nil]; 


for (UIView *subview in actionSheet.subviews) { 
    if ([subview isKindOfClass:[UIButton class]]) { 
     UIButton *button = (UIButton *)subview; 
     [button setBackgroundColor:[UIColor whiteColor]]; 
     [button setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted]; 

     [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; 
     [button setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected]; 
    } 
} 
// [actionSheet setBackgroundColor:[UIColor whiteColor]]; 
[actionSheet showInView:self.view]; 
+0

Mais je ne suis pas montrer actionsheet de la barre d'onglet 'utilise showInView j'ai essayé d'ajouter [actionSheet.superView addGestureRecognizer: tap] – Snigdha

+0

je pense problème est que la feuille d'action se chevauchent votre point de vue tout avec une vue transparente pourquoi vous obtenez pas le geste du robinet. –

+0

Oui alors comment pouvons-nous fermer cela lorsque l'utilisateur tape à l'extérieur de la feuille d'action – Snigdha

1

Salut c'est ma solution de rejeter le actionsheet lorsque vous appuyez sur l'extérieur

d'abord créer une vue de gérer le geste du robinet et la feuille d'action

@implementation MyClass 
{ 
    UIActionSheet *_myActionSheet; 
    UIView *_myTapView; 
} 

sur la méthode de délégué actionsheet

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    [_myTapView removeFromSuperview]; 
    _myTapView = [[UIView alloc] initWithFrame:actionSheet.superview.bounds]; 
    _myTapView.backgroundColor = [UIColor clearColor]; 

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)]; 
    tap.cancelsTouchesInView = NO; 
    [_myTapView addGestureRecognizer:tap]; 

    [actionSheet.superview insertSubview:_myTapView belowSubview:actionSheet]; 
} 

et gérer le geste du robinet

- (void)tapOut:(UIGestureRecognizer *)gestureRecognizer 
{ 
//dismiss the action sheet here 
    [_myActionSheet dismissWithClickedButtonIndex:<index> animated:YES]; 
}