You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.7 KiB

//
// GuideTheOperationImage.swift
// ShareCar
//
// Created by WeiChaoZheng on 2017/11/3.
// Copyright © 2017 jianYou. All rights reserved.
//
import UIKit
class GuideTheOperationImage: UIView {
var removeBlock:(()->Void)?
/// 0 1 2
var rectType = ""
///
var showImageView :UIImageView?
var showNextBtn = UIButton.init(type: .custom)
var areaRect : CGRect?
class func newInstance() -> GuideTheOperationImage? {
let nibView = Bundle.main.loadNibNamed("GuideTheOperationImage", owner: nil, options: nil);
if let view = nibView?.first as? GuideTheOperationImage {
return view
}
return nil
}
///
///
/// - Parameters:
/// - frame:
/// - shape: 0 1 2
/// - type: head location add
func setFrameAndShape(frame:CGRect, shape:String, type:String){
self.areaRect = frame;
self.rectType = shape;
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
if(type == "watch"){ // 165h
let imageFrame = CGRect.init(x: 20, y: screenHeight-frame.height-165-30, width:screenWidth , height: 165)
showImageView = UIImageView.init(frame: imageFrame)
showImageView?.image = UIImage.init(named: "设备指导图")
let btnFrame = CGRect.init(x: screenWidth-30-100, y: 75, width: 100, height: 52)
showNextBtn.frame = btnFrame
showNextBtn.setBackgroundImage(UIImage.init(named: "下一步指导图按钮"), for: .normal)
}else if(type == "add"){ // 165h
let imageFrame = CGRect.init(x: 0, y: frame.origin.y+frame.height, width:screenWidth , height: 165)
showImageView = UIImageView.init(frame: imageFrame)
showImageView?.image = UIImage.init(named: "添加新设备指导图")
let btnFrame = CGRect.init(x: screenWidth-30-100, y: screenHeight-52-45, width: 100, height: 52)
showNextBtn.frame = btnFrame
showNextBtn.setBackgroundImage(UIImage.init(named: "下一步指导图按钮"), for: .normal)
}else if(type == "location"){ // 165h
let imageFrame = CGRect.init(x: 0, y: screenHeight-frame.height-165-20, width:screenWidth , height: 165)
showImageView = UIImageView.init(frame: imageFrame)
showImageView?.image = UIImage.init(named: "定位指导图")
let btnFrame = CGRect.init(x: screenWidth-30-100, y: 75, width: 100, height: 52)
showNextBtn.frame = btnFrame
showNextBtn.setBackgroundImage(UIImage.init(named: "我知道了指导图按钮"), for: .normal)
}
if(showImageView != nil){
showImageView?.contentMode = .scaleAspectFit
self.addSubview(showImageView!)
self.addSubview(showNextBtn)
showNextBtn.addTarget(self, action: #selector(self.OKAction), for: .touchUpInside)
}
self.setNeedsDisplay() // draw
}
@objc func OKAction() {
if removeBlock != nil {
removeBlock!()
}
self.removeFromSuperview()
}
override func awakeFromNib() {
self.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(self.OKAction)))
}
override func draw(_ rect: CGRect) {
super.draw(rect)
if(self.areaRect != nil){
//
let context = UIGraphicsGetCurrentContext()!
context.clear(self.bounds); //
context.setFillColor(UIColor.black.withAlphaComponent(0.2).cgColor)
let bezPath = UIBezierPath.init(rect: self.bounds)
var addPath : UIBezierPath!
switch self.rectType {
case "0"://
addPath = UIBezierPath.init(roundedRect: self.areaRect!, cornerRadius: self.areaRect!.width/2)
break
case "1"://
addPath = UIBezierPath.init(roundedRect: self.areaRect!, cornerRadius: 5)
break
case "2"://
addPath = UIBezierPath.init(ovalIn: self.areaRect!)
break
default:
addPath = UIBezierPath.init()
break
}
bezPath.append(addPath.reversing())
context.addPath(bezPath.cgPath)
context.fillPath()
}
}
}