Skip to content

Commit

Permalink
update to swift 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckDeck committed Oct 10, 2018
1 parent 3c4e592 commit cb2ca52
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 149 deletions.
16 changes: 8 additions & 8 deletions ViewChaos/DrawView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class DrawView: UIView {
self.backgroundColor = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 0.2)
btnCaptureScreen.frame = CGRect(x: UIScreen.main.bounds.size.width - 90, y: UIScreen.main.bounds.size.height - 25, width: 90, height: 25)
btnCaptureScreen.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.5)
btnCaptureScreen.setTitle("启用截屏", for: UIControlState())
btnCaptureScreen.addTarget(self, action: #selector(DrawView.captureScreenClick(_:)), for: UIControlEvents.touchUpInside)
btnCaptureScreen.setTitle("启用截屏", for: UIControl.State())
btnCaptureScreen.addTarget(self, action: #selector(DrawView.captureScreenClick(_:)), for: UIControl.Event.touchUpInside)
addSubview(btnCaptureScreen)

btnCleanTrace.frame = CGRect(x: UIScreen.main.bounds.size.width - 150, y: UIScreen.main.bounds.size.height - 25, width: 50, height: 25)
btnCleanTrace.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.5)
btnCleanTrace.setTitle("清理", for: UIControlState())
btnCleanTrace.addTarget(self, action: #selector(DrawView.clearTraceClick(_:)), for: UIControlEvents.touchUpInside)
btnCleanTrace.setTitle("清理", for: UIControl.State())
btnCleanTrace.addTarget(self, action: #selector(DrawView.clearTraceClick(_:)), for: UIControl.Event.touchUpInside)
addSubview(btnCleanTrace)
btnCleanTrace.isHidden = true
}
Expand All @@ -61,13 +61,13 @@ class DrawView: UIView {

@objc func captureScreenClick(_ sender:UIButton) {
//这里用截图功能
if let title = sender.title(for: UIControlState())
if let title = sender.title(for: UIControl.State())
{
if title == "启用截屏"{
Chaos.toast("现在开始截图")
drawMode = .capture
self.backgroundColor = UIColor.clear
btnCaptureScreen.setTitle("保存", for: UIControlState())
btnCaptureScreen.setTitle("保存", for: UIControl.State())
}
else{
UIGraphicsBeginImageContextWithOptions(UIScreen.main.bounds.size, true, 0)//这个应该是设定一个区域
Expand All @@ -76,7 +76,7 @@ class DrawView: UIView {
UIImageWriteToSavedPhotosAlbum(imgCapture!, self, nil, nil)
self.backgroundColor = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 0.2)
Chaos.toast("保存截图成功")
btnCaptureScreen.setTitle("启用截屏", for: UIControlState())
btnCaptureScreen.setTitle("启用截屏", for: UIControl.State())
clearTrace()
drawMode = .draw
}
Expand All @@ -87,7 +87,7 @@ class DrawView: UIView {

@objc func clearTraceClick(_ sender:UIButton){
clearTrace()
btnCaptureScreen.setTitle("启用截屏", for: UIControlState())
btnCaptureScreen.setTitle("启用截屏", for: UIControl.State())
drawMode = .draw
}

Expand Down
10 changes: 5 additions & 5 deletions ViewChaos/LogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ class logTableViewCell: UITableViewCell {
lblMsg.text = msg
}
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = UIColor.clear
lblMsg.numberOfLines = 0
lblMsg.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(lblMsg)
let leftConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: contentView, attribute: NSLayoutAttribute.leading, multiplier: 1, constant: 10)
let rightConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal, toItem: contentView, attribute: NSLayoutAttribute.trailing, multiplier: 1, constant: -10)
let topConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: contentView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 3)
let bottomConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: contentView, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -3)
let leftConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal, toItem: contentView, attribute: NSLayoutConstraint.Attribute.leading, multiplier: 1, constant: 10)
let rightConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal, toItem: contentView, attribute: NSLayoutConstraint.Attribute.trailing, multiplier: 1, constant: -10)
let topConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: contentView, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 3)
let bottomConstraint = NSLayoutConstraint.init(item: lblMsg, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: contentView, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: -3)
NSLayoutConstraint.activate([leftConstraint,rightConstraint,topConstraint,bottomConstraint])
lblMsg.textColor = UIColor.white
lblMsg.font = UIFont.systemFont(ofSize: 12)
Expand Down
2 changes: 1 addition & 1 deletion ViewChaos/MarkInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TaggingView: UIView,AbstractView {
context.strokePath()
let str = String.init(format: "%.0f px", line.lineWidth)
let position = CGRect(x: line.centerPoint.x - 15 < 0 ? 3 : line.centerPoint.x - 15 , y: line.centerPoint.y - 6 < 3 ? 0 : line.centerPoint.y - 6 , width: 30, height: 16)
(str as NSString).draw(in: position, withAttributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 7),NSAttributedStringKey.foregroundColor:UIColor.red,NSAttributedStringKey.backgroundColor:UIColor(red: 1, green: 1, blue: 0, alpha: 0.5)])
(str as NSString).draw(in: position, withAttributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 7),NSAttributedString.Key.foregroundColor:UIColor.red,NSAttributedString.Key.backgroundColor:UIColor(red: 1, green: 1, blue: 0, alpha: 0.5)])
}
}

Expand Down
26 changes: 14 additions & 12 deletions ViewChaos/ViewChaos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension UIWindow:UIActionSheetDelegate {

}

open override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
open override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
switch self.chaosFeature
{
case ChaosFeature.none.rawValue:
Expand Down Expand Up @@ -336,12 +336,12 @@ class ViewChaos: UIView {
windowInfo.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.7)
windowInfo.isHidden = true
windowInfo.chaosName = "windowInfo"
windowInfo.windowLevel = UIWindowLevelAlert
windowInfo.windowLevel = UIWindow.Level.alert
lblInfo = UILabel(frame: windowInfo.bounds)
lblInfo.numberOfLines = 2
lblInfo.backgroundColor = UIColor.clear
lblInfo.lineBreakMode = NSLineBreakMode.byCharWrapping
lblInfo.autoresizingMask = [UIViewAutoresizing.flexibleHeight,UIViewAutoresizing.flexibleWidth]
lblInfo.autoresizingMask = [UIView.AutoresizingMask.flexibleHeight,UIView.AutoresizingMask.flexibleWidth]
//self.checkUpdate
left = 0
top = 0
Expand All @@ -351,7 +351,7 @@ class ViewChaos: UIView {
self.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)

let lbl = UILabel(frame: self.bounds)
lbl.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
lbl.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
lbl.textAlignment = NSTextAlignment.center
lbl.text = "V"
lbl.backgroundColor = UIColor(red: 0.253, green: 0.917, blue: 0.476, alpha: 1.0)
Expand Down Expand Up @@ -439,13 +439,14 @@ class ViewChaos: UIView {
}

@objc func handleTraceAddSubView(_ notif:Notification){
if let viewSuper = notif.object
if let viewSuper = notif.object as? UIWindow
{
if let view = (notif as NSNotification).userInfo!["subview" as NSObject] as? UIView{
if (viewSuper as AnyObject).isKind(of: UIWindow.self) && view != self{
(viewSuper as AnyObject).bringSubview(toFront: self)
if view != self{
viewSuper.bringSubviewToFront(self)
if viewChaosInfo != nil{
(viewSuper as AnyObject).bringSubview(toFront: viewChaosInfo!)
viewSuper.bringSubviewToFront(viewChaosInfo!)

}
}
}
Expand All @@ -458,7 +459,7 @@ class ViewChaos: UIView {
self.window?.addSubview(viewBound)
let p = self.window?.convert(view.bounds, from: view)
viewBound.frame = p!
UIView.animate(withDuration: 0.3, delay: 0, options: [UIViewAnimationOptions.allowUserInteraction,UIViewAnimationOptions.repeat,UIViewAnimationOptions.autoreverse], animations: { () -> Void in
UIView.animate(withDuration: 0.3, delay: 0, options: [UIView.AnimationOptions.allowUserInteraction,UIView.AnimationOptions.repeat,UIView.AnimationOptions.autoreverse], animations: { () -> Void in
UIView.setAnimationRepeatCount(2)
self.viewBound.alpha = 0
}, completion: { (finished) -> Void in
Expand Down Expand Up @@ -1200,7 +1201,7 @@ class ToastLable:UILabel {
animationGroup.duration = forwardAnimation.duration + backWardAnimation.duration + waitAnimationDuration
animationGroup.isRemovedOnCompletion = false
//animationGroup.delegate = self
animationGroup.fillMode = kCAFillModeForwards
animationGroup.fillMode = CAMediaTimingFillMode.forwards
self.layer.add(animationGroup, forKey: "animation")
}
override func sizeToFit() {
Expand All @@ -1218,12 +1219,13 @@ class ToastLable:UILabel {
}
}
override func drawText(in rect: CGRect) {
super.drawText(in: UIEdgeInsetsInsetRect(rect, self.textInsets!))
super.drawText(in: rect.inset(by: self.textInsets ?? UIEdgeInsets()))
// super.drawText(in: UIEdgeInsetsInsetRect(rect, self.textInsets!))
}
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
var rect = bounds
if let txt = self.text{
rect.size = (txt as NSString).boundingRect(with: CGSize(width: CGFloat(self.maxWidth!) - self.textInsets!.left - self.textInsets!.right, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font:self.font], context: nil).size
rect.size = (txt as NSString).boundingRect(with: CGSize(width: CGFloat(self.maxWidth!) - self.textInsets!.left - self.textInsets!.right, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font:self.font], context: nil).size
}
return rect
}
Expand Down
Loading

0 comments on commit cb2ca52

Please sign in to comment.