2017-04-04 2 views
0

in meinem iOS swift 3.0 Anwendung entlassen, präsentierte ich UIAlertController Blatt Instanz über meine aktuelle ViewController. Aber ich möchte das Blatt nicht ausblenden, wenn ich außerhalb eines Bereichs des Blattes (gedimmter halbtransparenter Hintergrund) klopfte, weil ich bereits eine Aktion abbrechen muss. Irgendeine Idee?nicht UialertController Blatt mit Tippen Geste außerhalb Dialogbereich in iOS

Ich habe MGSwipeTableViewCell mit mehr Knopf. Wenn der Benutzer auf die Schaltfläche "Mehr" klickt, wird der folgende Code ausgeführt.

func onClickMore(for vmCell: VmCell) { 
    let sheet = UIAlertController(title: vmCell.vmItem?.vmNameWithoutIp, message: vmCell.vmItem?.ipAddress, preferredStyle: .actionSheet) 

    sheet.addAction(UIAlertAction(title: "Create Ticket", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Start VM", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Restart VM", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Stop VM", style: .destructive) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Cancel", style: .cancel) { (action: UIAlertAction) in 

    }) 

    present(sheet, animated: true) { 
     sheet.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)) 
    } 
} 
+0

siehe diesen Link: ht tp: //stackoverflow.com/questions/8632944/any-way-to-prevent-uiactionsheet-from-being-dismissed-when-user-clicks-a-button – Aashish1aug

+0

http://stackoverflow.com/questions/25466718/ uialertcontroller-handle-ablehnen-auf-klicken-außerhalb-ipad –

Antwort

2

für UIAlertController Typ als Alarm

Sie die

self.present(alertController, animated: true, completion: {() -> Void in 
alertController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil) 
}) 

auf dieser Aktion sample project

die Gestenerkenner zu alertController hinzufügen Super für handhaben die Anwenderwechsel herunterladen nichts tun

Update

let alertController = UIAlertController(title: "Do something", message: "With this", preferredStyle: .alert) 
    alertController.addAction(UIAlertAction(title: "Done", style: .default) { action in 
     // perhaps use action.title here 
    }) 

    self.present(alertController, animated: true, completion: {() -> Void in 


     alertController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)) 
    }) 

für UIAlertController Typ als actionSheet

Sie die sample project herunterladen

Sie dies auf zwei Arten tun können

Option 1

alert.view.superview.subviews[0] isUserInteractionEnabled = false 

Option 2

alert.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)) 

für z

self.present(sheet, animated: true, completion: {() -> Void in 
    // sheet.view.superview?.subviews[0].isUserInteractionEnabled = false; 
     sheet.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)) 

    }) 

vollständigen Code

let sheet = UIAlertController(title: "karthik", message: "check with", preferredStyle: .actionSheet) 

    sheet.addAction(UIAlertAction(title: "Create Ticket", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Start VM", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Restart VM", style: .default) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Stop VM", style: .destructive) { (action: UIAlertAction) in 

    }) 

    sheet.addAction(UIAlertAction(title: "Cancel", style: .cancel) { (action: UIAlertAction) in 

    }) 



    self.present(sheet, animated: true, completion: {() -> Void in 
    // sheet.view.superview?.subviews[0].isUserInteractionEnabled = false; 
     sheet.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)) 

    }) 
+1

sorry. Es funktioniert nicht – appleBoy21

+0

@Sanket - können Sie die Frage aktualisieren, funktioniert es perfekt in meiner Seite, warten, ich werde das Beispielprojekt beifügen –

+0

ja. Ich füge auch meinen Code – appleBoy21

Verwandte Themen