Finb / V2ex-Swift

An iOS client written in Swift for V2EX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

在话题详情页里,回复评论如果没有登录它没提示

atjiu opened this issue · comments

commented

我尝试着加了一下,但V2Inform("请先登录") ,但它不显示

然后在,网上找了一段toast的代码

extension UIViewController {
    
    func showToast(message : String) {
        
        let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
        toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
        toastLabel.textColor = UIColor.white
        toastLabel.textAlignment = .center;
        toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
        toastLabel.text = message
        toastLabel.alpha = 1.0
        toastLabel.layer.cornerRadius = 10;
        toastLabel.clipsToBounds  =  true
        self.view.addSubview(toastLabel)
        UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
            toastLabel.alpha = 0.0
        }, completion: {(isCompleted) in
            toastLabel.removeFromSuperview()
        })
    } }

它就显示了,大佬看一下呗,加个提示会友好些

commented

我测试后发现有弹出 请先登录 的提示呀, 是未登录时点回复这个操作么?

代码位置在这,这个方法会确保代码在登录后执行,否则弹出请先登录的提示

V2User.sharedInstance.ensureLoginWithHandler {

commented

没登录的时候点击没效果
untitle

commented

刚调试了一下,确实有这个问题

原因是
UIActionSheet 在iOS11下(也可能之前某个版本) 的实现机制是创建一个 window容器,然后把ActionSheet显示在这个window上
第三方库 SVProgressHUD 显示时,需要获取最上层的window来做容器显示弹框。然后就获取到了UIActionSheet创建的那个
但是这个时候UIActionSheet已经在消失了,SVProgressHUD就跟着一起消失没显示了。

https://github.com/SVProgressHUD/SVProgressHUD/blob/7f676d51905ede045ca5dcaf82d4ba0d9f96addf/SVProgressHUD/SVProgressHUD.m#L1339

解决办法先暂时强制设置SVProgressHUD 的显示容器为当前程序的window吧,对这个APP正好合适
4ba3cec

感谢dalao反馈,我一直登录使用没碰到这个问题 - -

commented

明白了,谢谢