|
@@ -220,22 +220,12 @@ open class KSMediaPickerPreviewView: UIView {
|
|
|
return changeSizeButton
|
|
|
}()
|
|
|
|
|
|
- private let _zoomButton = {() -> UIButton in
|
|
|
- let zoomButton = UIButton(type: .custom)
|
|
|
- zoomButton.setImage(UIImage(named: "icon_mediaPicker_preview_aspect_fit"), for: .normal)
|
|
|
- zoomButton.setImage(UIImage(named: "icon_mediaPicker_preview_aspect_fill"), for: .selected)
|
|
|
- zoomButton.backgroundColor = UIColor.ks_black.withAlphaComponent(0.3)
|
|
|
- return zoomButton
|
|
|
- }()
|
|
|
-
|
|
|
override public init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|
|
|
backgroundColor = .ks_background
|
|
|
clipsToBounds = true
|
|
|
addSubview(_scrollview)
|
|
|
|
|
|
- _zoomButton.addTarget(self, action: #selector(_didClick(zoomButton:)), for: .touchUpInside)
|
|
|
- addSubview(_zoomButton)
|
|
|
_changeSizeButton.addTarget(self, action: #selector(_didClick(changeSizeButton:)), for: .touchUpInside)
|
|
|
addSubview(_changeSizeButton)
|
|
|
|
|
@@ -258,34 +248,14 @@ open class KSMediaPickerPreviewView: UIView {
|
|
|
var viewY = (windowHeight-viewH)*0.5
|
|
|
_scrollview.frame = CGRect(x: viewX, y: viewY, width: viewW, height: viewH)
|
|
|
|
|
|
- viewW = _zoomButton.sizeThatFits(windowSize).width+12.0
|
|
|
- viewH = CGFloat(20.0)
|
|
|
- viewX = CGFloat(10.0)
|
|
|
- viewY = windowHeight-viewH-10.0
|
|
|
- _zoomButton.frame = CGRect(x: viewX, y: viewY, width: viewW, height: viewH)
|
|
|
- _zoomButton.layer.cornerRadius = viewH*0.5
|
|
|
-
|
|
|
viewW = 30.0
|
|
|
viewH = viewW
|
|
|
+ viewX = CGFloat(10.0)
|
|
|
viewY = windowHeight-viewH-10.0
|
|
|
_changeSizeButton.frame = CGRect(x: viewX, y: viewY, width: viewW, height: viewH)
|
|
|
// _changeSizeButton.layer.cornerRadius = viewH*0.5
|
|
|
}
|
|
|
|
|
|
- //isSelected = false 显示留白 isSelected = true 显示充满
|
|
|
- @objc private func _didClick(zoomButton: UIButton) {
|
|
|
- let scrollviewZoomScale = _scrollview.zoomScale
|
|
|
- let zoomScale: CGFloat
|
|
|
- if scrollviewZoomScale == 1.0 {
|
|
|
- zoomScale = _scrollview.minimumZoomScale
|
|
|
- zoomButton.isSelected = true
|
|
|
- } else {
|
|
|
- zoomScale = 1.0
|
|
|
- zoomButton.isSelected = false
|
|
|
- }
|
|
|
- _scrollview.setZoomScale(zoomScale, animated: true)
|
|
|
- }
|
|
|
-
|
|
|
@objc private func _didClick(changeSizeButton: UIButton) {
|
|
|
let isChangedSize = changeSizeButton.isSelected
|
|
|
changeSizeButton.isSelected = !isChangedSize
|
|
@@ -320,7 +290,6 @@ open class KSMediaPickerPreviewView: UIView {
|
|
|
}
|
|
|
let asset = itemModel.asset
|
|
|
if asset.mediaType == .video {
|
|
|
- _zoomButton.isHidden = true
|
|
|
_videoView.isHidden = false
|
|
|
_scrollview.isHidden = true
|
|
|
_changeSizeButton.isHidden = true
|
|
@@ -353,7 +322,6 @@ open class KSMediaPickerPreviewView: UIView {
|
|
|
|
|
|
let windowWidth = mainSize.width
|
|
|
if _isStandard {
|
|
|
- _zoomButton.isHidden = true
|
|
|
_normalScrollViewSize = CGSize(width: windowWidth, height: windowWidth)
|
|
|
if pixelWidth == pixelHeight {
|
|
|
_changeSizeButton.isHidden = true
|
|
@@ -390,8 +358,6 @@ open class KSMediaPickerPreviewView: UIView {
|
|
|
}
|
|
|
} else {
|
|
|
_changeSizeButton.isHidden = true
|
|
|
- _zoomButton.isSelected = false
|
|
|
- _zoomButton.isHidden = _changeSizeButton.isSelected
|
|
|
}
|
|
|
_scrollview.set(frame: CGRect(origin: .zero, size: _changeSizeButton.isSelected ? _minScrollViewSize : _normalScrollViewSize), isNeedLayoutSubviews: true)
|
|
|
setNeedsLayout()
|