在Swift中为iPad滑过自定义警报视图

时间:2017-01-09 05:39:43

标签: ios swift ipad uiview

我似乎在使用我创建的自定义警报视图类时遇到了一些问题。当应用程序全屏运行时,警报将显示在显示屏的中央,但是,当应用程序在幻灯片中运行时,警报将无法正确显示。有关为什么会这样的想法?我班上的代码如下:

import UIKit

class AlertView: UIView {


    @IBOutlet weak var dismissButton:UIButton!
    @IBOutlet weak var errorLabel:UILabel!
    @IBOutlet weak var errorImage:UIImageView!




    func setAlertView(message:String) {

        errorLabel.textColor = .white

        self.backgroundColor = greyColor
        self.layer.borderWidth = 0
        self.layer.cornerRadius = 10

        self.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
        self.alpha = 0
        errorLabel.text = message
        UIView.animate(withDuration: 0.4) {
            self.alpha = 1
            self.transform = CGAffineTransform.identity
        }

    }



    @IBAction func dismissAlertView() {

        UIView.animate(withDuration: 0.3, animations: {
            self.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
            self.alpha = 0
        }) {(succes:Bool) in
            self.removeFromSuperview()
        }

        NotificationCenter.default.post(name: Notification.Name(rawValue: "ErrorDismissed"), object: nil, userInfo: nil)

    }


    override init (frame : CGRect) {
        super.init(frame : frame)
    }

    convenience init () {
        self.init(frame:CGRect.zero)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }



}

0 个答案:

没有答案