Ios UIAlertController,关闭时是否消除动画?

Ios UIAlertController,关闭时是否消除动画?,ios,uialertcontroller,Ios,Uialertcontroller,这是一张简单的行动单 let choice = UIAlertController(title: "Choose", message: nil, preferredStyle: .actionSheet) choice.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in self.happyCamera() })) choice.addAct

这是一张简单的行动单

let choice = UIAlertController(title: "Choose", message: nil, preferredStyle: .actionSheet)

choice.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
        self.happyCamera() }))

choice.addAction(UIAlertAction(title: "Album", style: .default, handler: { _ in
        self.happyAlbum() }))

choice.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))

somewhere?.present(choice, animated: false, completion: nil)
当动作表出现时(请注意,当前动画为false),它只需点击屏幕,而不是奇奇动画

但是,当用户点击三个选项中的一个,或点击“关闭”时,操作表将使用cheesey动画离开屏幕

(特别是在10.3中,它从屏幕上向下滑动。)

有没有办法关闭退出动画


如果您将UIAlertController子类化…它不工作? 正如DS在下面所建议的,您可以将UIAlertController子类化

然而,奇怪的是,它什么也没做。这是一个测试

func _test() {
    
    let msg = SuperiorUIAlertController(
        title: "Hello", message: "Hello",
        preferredStyle: UIAlertControllerStyle.alert)
    msg.addAction(UIAlertAction(
        title: "OK", style: UIAlertActionStyle.default,
        handler: nil))
    
    let win = UIWindow(frame: UIScreen.main.bounds)
    let vc = UIViewController()
    vc.view.backgroundColor = .clear
    win.rootViewController = vc
    win.windowLevel = UIWindowLevelAlert + 1
    win.makeKeyAndVisible()    
    vc.present(msg, animated: false, completion: nil)
}

class SuperiorUIAlertController: UIAlertController {
    
    override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
        
        print("You should see this! \(flag)")
        self.dismiss(animated: false, completion: completion)
    }
}

事实上,文本“You should see this”永远不会出现

这是您可以覆盖viewController的Disclose方法的又一种方式。如果不想覆盖其他动画,请检查动画标志值或在下面的方法中创建标志

使您的AlertController全球化

var choice = UIAlertController()   
确保在显示警报的viewController中添加此方法

在没有动画的情况下关闭显示的警报,如下图所示

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    self.choice.dismiss(animated: false, completion: nil)
}

我不想回答我自己的问题,但截至2017年底,没有办法。奇怪吧


希望这一事实能对其他人有所帮助。

在手柄中添加Disclease。您现在的动画设置为false,而不是Disclease。@Fattie请看我更新的AnswerDisclease(动画:completion:)是UIViewController的实例方法之一。检查它是的。您可以覆盖它的一种方法。我已经在回答中指出了。奇怪的是,这不起作用。覆盖甚至没有被调用,实际上:/presenting view控制器中的
discouse
确实被调用了,我一直觉得很奇怪。我很欣赏这部作品,@DSDharma,谢谢。但是,它会闪烁,因为您正在中断警报本身的解除,以及灰色背景。不管怎样,谢谢,谢谢。我也有同样的烦恼——你有没有可能向苹果提交一份bug报告?如果不是,我正在考虑这样做。可笑吧@A.L.Strine你知道,我只是不费心——苹果通常在5-10年内不会修复bug,那么为什么要费心:/