|
@@ -14,6 +14,7 @@ class PublishNewPopView: UIView {
|
|
|
var titles : Array<String>?
|
|
|
var columnCount : Int = 4
|
|
|
var scrollView : UIScrollView?
|
|
|
+ var shutImgView : UIImageView?
|
|
|
typealias SelectClosure = (Int) -> Void
|
|
|
var selectClosure : SelectClosure?
|
|
|
|
|
@@ -28,19 +29,22 @@ class PublishNewPopView: UIView {
|
|
|
let effect = UIBlurEffect(style: UIBlurEffect.Style.light)
|
|
|
let effectView = UIVisualEffectView(effect: effect)
|
|
|
effectView.frame = publishNewPopView.bounds
|
|
|
- effectView.alpha = 0.8
|
|
|
+ effectView.alpha = 1
|
|
|
+ effectView.addTapGesture(1, target: publishNewPopView, action: #selector(close))
|
|
|
publishNewPopView.addSubview(effectView)
|
|
|
|
|
|
publishNewPopView.imageStrs = imageStrs
|
|
|
publishNewPopView.titles = titles
|
|
|
publishNewPopView.columnCount = columnCount
|
|
|
publishNewPopView.selectClosure = selectClosure
|
|
|
-
|
|
|
+ publishNewPopView.setupMainView()
|
|
|
+ publishNewPopView.setupItem()
|
|
|
+ publishNewPopView.setupBottom()
|
|
|
}
|
|
|
|
|
|
func setupMainView() {
|
|
|
- let scrollView = UIScrollView(frame: CGRect(x: 0, y: kScreenHeight-170-48-kSafeTabBarHeight, width: kScreenWidth, height: 170))
|
|
|
- let pages = (titles?.count ?? 1 - 1) / columnCount + 1
|
|
|
+ let scrollView = UIScrollView(frame: CGRect(x: 0, y: kScreenHeight-130-48-kSafeTabBarHeight, width: kScreenWidth, height: 90))
|
|
|
+ let pages = 1
|
|
|
scrollView.contentSize = CGSize(width: scrollView.frame.size.width * CGFloat(pages), height: 0)
|
|
|
scrollView.isPagingEnabled = true
|
|
|
scrollView.showsHorizontalScrollIndicator = false
|
|
@@ -56,19 +60,79 @@ class PublishNewPopView: UIView {
|
|
|
for i in 0 ..< (titles?.count ?? 0) {
|
|
|
let x : CGFloat = (CGFloat(i + 1) * hSpacing) + CGFloat(CGFloat(i) * itemWidth)
|
|
|
let y : CGFloat = 0.0
|
|
|
- let button = PublishNewPopButton(frame: CGRect(x: x, y: y, width: itemWidth, height: itemHeight))
|
|
|
- button.tag = 1000 + 1
|
|
|
+ let button = UIButton(frame: CGRect(x: x, y: 90, width: itemWidth, height: itemHeight))
|
|
|
+ button.tag = 1000 + i
|
|
|
button.setTitle(titles?[i], for: UIControl.State.normal)
|
|
|
button.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
button.titleLabel?.font = kRegularFont14
|
|
|
button.setImage(kImage(name: imageStrs?[i] ?? "") , for: UIControl.State.normal)
|
|
|
button.imageView?.contentMode = .center
|
|
|
-// button.addTarget(self, action: #selector(selectClick(:)), for: UIControl.Event.touchUpInside)
|
|
|
-
|
|
|
+ button.addTarget(self, action: #selector(selectClick(button:)), for: UIControl.Event.touchUpInside)
|
|
|
+ scrollView?.addSubview(button)
|
|
|
+ button.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 10)
|
|
|
+
|
|
|
+ UIView.animate(withDuration: 0.3, delay: TimeInterval(CGFloat(i) * 0.03), usingSpringWithDamping: 0.7, initialSpringVelocity: 0.04, options: UIView.AnimationOptions.allowUserInteraction, animations: { [weak button] in
|
|
|
+ button?.frame = CGRect(x: x, y: y, width: itemWidth, height: itemHeight)
|
|
|
+ }) { (finished) in}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func setupBottom() {
|
|
|
+
|
|
|
+ let view = UIView()
|
|
|
+ view.isUserInteractionEnabled = false
|
|
|
+ addSubview(view)
|
|
|
+ view.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(-kSafeTabBarHeight)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(48)
|
|
|
+ }
|
|
|
+
|
|
|
+ let shutImgView = UIImageView()
|
|
|
+ shutImgView.image = kImage(name: "publish_btn_close")
|
|
|
+ shutImgView.isUserInteractionEnabled = false
|
|
|
+ self.shutImgView = shutImgView
|
|
|
+ view.addSubview(shutImgView)
|
|
|
+ shutImgView.snp.makeConstraints { (make) in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ make.size.equalTo(24)
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.3, animations: {
|
|
|
+ [weak self] in
|
|
|
+ self?.shutImgView?.transform = CGAffineTransform(rotationAngle: 0.0)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func selectClick(button:UIButton) {
|
|
|
+ UIView.animate(withDuration: 0.25, animations: {
|
|
|
+ [weak self] in
|
|
|
+ self?.alpha = 0
|
|
|
+ }) { [weak self] (finished) in
|
|
|
+ self?.removeFromSuperview()
|
|
|
+ }
|
|
|
+ if let selectClosure = selectClosure {
|
|
|
+ selectClosure(button.tag - 1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func close() {
|
|
|
+ UIView.animate(withDuration: 0.3, animations: {
|
|
|
+ [weak self] in
|
|
|
+ self?.shutImgView?.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 4))
|
|
|
+ })
|
|
|
+ for i in 0 ..< (titles?.count ?? 0) {
|
|
|
+ let button = self.viewWithTag(1000 + i)
|
|
|
+ guard let width = button?.frame.width else { return }
|
|
|
+ guard let height = button?.frame.height else { return }
|
|
|
+ guard let x = button?.frame.origin.x else { return }
|
|
|
+ let y = 90
|
|
|
+
|
|
|
+ UIView.animate(withDuration: 0.3, delay: TimeInterval(0.03 * CGFloat((titles?.count ?? 0) - i)) , usingSpringWithDamping: 0.7, initialSpringVelocity: 0.04, options: UIView.AnimationOptions.allowUserInteraction, animations: { [weak button] in
|
|
|
+ button?.frame = CGRect(x: x, y: CGFloat(y), width:width, height: height)
|
|
|
+ }) { [weak self] (finished) in
|
|
|
+ self?.removeFromSuperview()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// @objc func selectClick(sender:PublishNewPopButton) {
|
|
|
-//
|
|
|
-// }
|
|
|
}
|