Commit 13f9c6ab authored by yqz's avatar yqz

Merge branch 'Purchases' into Pay

* Purchases:
  内购 样式修改

# Conflicts:
#	PhoneManager/Class/Session/NoAds/HomeNoAdsViewController.swift
parents b2ff9d1b b4b0ecc2
...@@ -159,6 +159,7 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource { ...@@ -159,6 +159,7 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource {
sview.setTitle(content, for: .normal) sview.setTitle(content, for: .normal)
sview.setTitleColor(color, for: .normal) sview.setTitleColor(color, for: .normal)
sview.titleLabel?.font = font sview.titleLabel?.font = font
sview.isSelected = false;
sview.sizeToFit() sview.sizeToFit()
let attributes: [NSAttributedString.Key: Any] = [ let attributes: [NSAttributedString.Key: Any] = [
...@@ -168,7 +169,7 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource { ...@@ -168,7 +169,7 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource {
] ]
let attributedString = NSAttributedString(string: content, attributes: attributes) let attributedString = NSAttributedString(string: content, attributes: attributes)
sview.setAttributedTitle(attributedString, for: .normal) sview.setAttributedTitle(attributedString, for: .normal)
sview.addTarget(self, action: #selector(terms), for: .touchUpInside) sview.addTarget(self, action: #selector(terms(_:)), for: .touchUpInside)
sview.sizeToFit() sview.sizeToFit()
contentScroll.addSubview(sview) contentScroll.addSubview(sview)
return sview return sview
...@@ -199,6 +200,41 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource { ...@@ -199,6 +200,41 @@ class HomeNoAdsViewController: UIViewController, NoAdsStackDataSource {
return sview return sview
}() }()
private lazy var privavye_Label: UILabel = {
let priva = UILabel()
priva.font = UIFont.systemFont(ofSize: 14)
priva.textColor = .gray
priva.text = ""
priva.numberOfLines = 0
priva.clipsToBounds = true
priva.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(labelTapped(_:)))
priva.addGestureRecognizer(tap)
contentScroll.addSubview(priva)
return priva
}()
@objc private func labelTapped(_ gesture: UITapGestureRecognizer) {
let location = gesture.location(in: privavye_Label)
let strs:NSString = "privacy policy"
let frssss = strs.boundingRect(with: CGSizeMake(.infinity, .infinity), options: .truncatesLastVisibleLine, attributes: [NSAttributedString.Key.font : privavye_Label.font], context: nil)
let frame1 = CGRectMake(0, privavye_Label.height-25, CGRectGetWidth(frssss), 25)
let frame2 = CGRectMake(CGRectGetWidth(frssss)+20, privavye_Label.height-25, 90, 25)
if frame1.contains(location) {
Print("点击了隐私")
let vc:PrivacyPolicyWebViewController = PrivacyPolicyWebViewController()
vc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(vc, animated: true)
}else if frame2.contains(location){
Print("点击了terms")
let vc:TermOfUseWebViewController = TermOfUseWebViewController()
vc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(vc, animated: true)
}
}
private let data:[[String:String]] = [ private let data:[[String:String]] = [
["icon":"ic_unsel_com","t":"Intelligent cleaning of similar photos"], ["icon":"ic_unsel_com","t":"Intelligent cleaning of similar photos"],
["icon":"ic_unsel_com","t":"Unlimited usage times"], ["icon":"ic_unsel_com","t":"Unlimited usage times"],
...@@ -265,12 +301,31 @@ extension HomeNoAdsViewController : UIScrollViewDelegate { ...@@ -265,12 +301,31 @@ extension HomeNoAdsViewController : UIScrollViewDelegate {
HomePayModel.share.restore() HomePayModel.share.restore()
} }
@objc func terms() -> Void { @objc func terms(_ sender:UIButton) -> Void {
DispatchQueue.main.async {[weak self] in DispatchQueue.main.async {[weak self] in
guard let self else {return} guard let self else {return}
let vc:TermOfUseWebViewController = TermOfUseWebViewController() sender.isSelected = !sender.isSelected
vc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(vc, animated: true) let strs:NSString = sender.isSelected ? "We offer 1-year and lifetime subscriptions. The price is clearly displayed within the application.\n\n·After the purchase confirmation, your iTunes account will be charged.\n·Unless the automatic update is turned off at least 24 hours before the end of the current cycle, the subscription will be automatically updated.\n·Your account will be renewed within 24 hours before the end of the current cycle cost.\n·You can go to the \"Account Settings\" in the iTunes store to manage your subscriptions and turn off auto renewal.\n·If provided, if you choose to use our free trial version, any unused portion during the free trial period will become invalid when you purchase a publication subscription, if applicable.\n·If you choose not to purchase the AI PhoneManager Pro version, you can continue to use it for free and enjoy PhoneManager.\n\nYour personal data is securely stored in PhoneManager, please make sure to read our \nprivacy policy and terms of use." : ""
let attribtit = NSMutableAttributedString(string:strs as String , attributes: [:])
if strs.length > 3 {
let rang = strs.range(of: "privacy policy")
attribtit.addAttributes([NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 14),NSAttributedString.Key.underlineStyle:NSUnderlineStyle.single.rawValue,.link:"appscheme://private"], range: rang)
let rang1 = strs.range(of: "terms of use")
attribtit.addAttributes([NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 14),NSAttributedString.Key.underlineStyle:NSUnderlineStyle.single.rawValue,.link:"appscheme://terms"], range: rang1)
}
privavye_Label.attributedText = attribtit
self.view.layoutIfNeeded()
DispatchQueue.main.async {
let height = CGRectGetMaxY(self.privavye_Label.frame)
self.contentScroll.contentSize = CGSize(width: 0, height: height + 30)
}
// let vc:TermOfUseWebViewController = TermOfUseWebViewController()
// vc.hidesBottomBarWhenPushed = true
// self.navigationController?.pushViewController(vc, animated: true)
} }
} }
...@@ -343,8 +398,13 @@ extension HomeNoAdsViewController : UIScrollViewDelegate { ...@@ -343,8 +398,13 @@ extension HomeNoAdsViewController : UIScrollViewDelegate {
private func setUI() -> Void { private func setUI() -> Void {
topBackimg.snp.makeConstraints { make in topBackimg.snp.makeConstraints { make in
<<<<<<< HEAD
make.left.right.equalToSuperview() make.left.right.equalToSuperview()
make.top.equalToSuperview().offset(-20) make.top.equalToSuperview().offset(-20)
=======
make.left.right.top.equalToSuperview()
make.height.equalTo(topBackimg.snp.width).multipliedBy(182.0/375.0)
>>>>>>> Purchases
} }
closeBtn.snp.makeConstraints { make in closeBtn.snp.makeConstraints { make in
...@@ -411,12 +471,18 @@ extension HomeNoAdsViewController : UIScrollViewDelegate { ...@@ -411,12 +471,18 @@ extension HomeNoAdsViewController : UIScrollViewDelegate {
make.centerY.equalTo(ppBtn) make.centerY.equalTo(ppBtn)
make.right.equalTo(buybut.snp.right) make.right.equalTo(buybut.snp.right)
} }
privavye_Label.snp.makeConstraints { make in
make.left.equalTo(ppBtn.snp.left)
make.right.equalTo(restoreBtn.snp.right)
make.top.equalTo(ppBtn.snp.bottom).offset(15)
}
self.type = 0 self.type = 0
self.view.layoutIfNeeded() self.view.layoutIfNeeded()
DispatchQueue.main.asyncAfter(deadline: .now()+0.1) { DispatchQueue.main.asyncAfter(deadline: .now()+0.1) {
self.buybut.layer.cornerRadius = CGRectGetHeight(self.buybut.frame) / 2.0 self.buybut.layer.cornerRadius = CGRectGetHeight(self.buybut.frame) / 2.0
self.scroll.contentSize = CGSize(width: CGRectGetWidth(self.scroll.frame) * 3.0, height: 0) self.scroll.contentSize = CGSize(width: CGRectGetWidth(self.scroll.frame) * 3.0, height: 0)
let height = CGRectGetMaxY(self.restoreBtn.frame) let height = CGRectGetMaxY(self.privavye_Label.frame)
self.contentScroll.contentSize = CGSize(width: 0, height: height + 30) self.contentScroll.contentSize = CGSize(width: 0, height: height + 30)
} }
} }
......
...@@ -45,17 +45,15 @@ class HomePayView:UIView { ...@@ -45,17 +45,15 @@ class HomePayView:UIView {
} }
lazy var ppBtn:UIButton = { lazy var ppBtn:UIButton = {
let sview:UIButton = UIButton() let sview:UIButton = UIButton()
let content:String = "Privacy Policy" let content:String = "Terms"
let font = UIFont.systemFont(ofSize: 12.RW(), weight: .medium) let font = UIFont.systemFont(ofSize: 12.RW(), weight: .medium)
let color = UIColor.colorWithHex(hexStr: black6Color) let color = UIColor.colorWithHex(hexStr: black6Color)
sview.setTitle(content, for: .normal) sview.setTitle(content, for: .normal)
sview.setTitleColor(color, for: .normal) sview.setTitleColor(color, for: .normal)
sview.titleLabel?.font = font sview.titleLabel?.font = font
sview.sizeToFit() sview.sizeToFit()
sview.isSelected = false
let attributes: [NSAttributedString.Key: Any] = [ let attributes: [NSAttributedString.Key: Any] = [
.font: font, .font: font,
.foregroundColor: color, .foregroundColor: color,
...@@ -72,7 +70,7 @@ class HomePayView:UIView { ...@@ -72,7 +70,7 @@ class HomePayView:UIView {
lazy var touBtn:UIButton = { lazy var touBtn:UIButton = {
let sview:UIButton = UIButton() let sview:UIButton = UIButton()
let content:String = "Terms of Use" let content:String = "Restore"
let font = UIFont.systemFont(ofSize: 12.RW(), weight: .medium) let font = UIFont.systemFont(ofSize: 12.RW(), weight: .medium)
let color = UIColor.colorWithHex(hexStr: black6Color) let color = UIColor.colorWithHex(hexStr: black6Color)
...@@ -139,20 +137,20 @@ class HomePayView:UIView { ...@@ -139,20 +137,20 @@ class HomePayView:UIView {
backgroundColor = .white backgroundColor = .white
restoreBtn = UIButton() // restoreBtn = UIButton()
restoreBtn?.setTitle("Restore Purchase", for: .normal) // restoreBtn?.setTitle("Restore Purchase", for: .normal)
restoreBtn?.setTitleColor(UIColor.colorWithHex(hexStr: "#B3B3B3"), for: .normal) // restoreBtn?.setTitleColor(UIColor.colorWithHex(hexStr: "#B3B3B3"), for: .normal)
restoreBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular) // restoreBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
restoreBtn?.addTarget(self, action: #selector(restoreTouch), for: .touchUpInside) // restoreBtn?.addTarget(self, action: #selector(restoreTouch), for: .touchUpInside)
self.addSubview(restoreBtn!) // self.addSubview(restoreBtn!)
//
restoreBtn?.snp.makeConstraints { make in // restoreBtn?.snp.makeConstraints { make in
make.top.equalToSuperview().offset(statusBarHeight + 10) // make.top.equalToSuperview().offset(statusBarHeight + 10)
make.left.equalToSuperview().offset(15) // make.left.equalToSuperview().offset(15)
} // }
// 确保按钮大小自适应 // 确保按钮大小自适应
restoreBtn?.sizeToFit() // restoreBtn?.sizeToFit()
closeBtn = UIButton() closeBtn = UIButton()
closeBtn?.setImage(UIImage(named: "home_pay_close"), for: .normal) closeBtn?.setImage(UIImage(named: "home_pay_close"), for: .normal)
...@@ -160,7 +158,8 @@ class HomePayView:UIView { ...@@ -160,7 +158,8 @@ class HomePayView:UIView {
self.addSubview(closeBtn!) self.addSubview(closeBtn!)
closeBtn?.snp.makeConstraints { make in closeBtn?.snp.makeConstraints { make in
make.centerY.equalTo(restoreBtn!) // make.centerY.equalTo(restoreBtn!)
make.top.equalToSuperview().offset(statusBarHeight + 10)
make.right.equalToSuperview().offset(-15) make.right.equalToSuperview().offset(-15)
make.width.height.equalTo(28) make.width.height.equalTo(28)
} }
...@@ -278,42 +277,33 @@ class HomePayView:UIView { ...@@ -278,42 +277,33 @@ class HomePayView:UIView {
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
}) })
appleLabel = UILabel() appleLabel = UILabel()
appleLabel?.text = " Secured with Apple" appleLabel?.text = " Secured with Apple"
appleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .bold) appleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .bold)
appleLabel?.textColor = UIColor.colorWithHex(hexStr: black3Color) appleLabel?.textColor = UIColor.colorWithHex(hexStr: black3Color)
self.addSubview(appleLabel!) self.addSubview(appleLabel!)
self.addSubview(ppBtn)
self.addSubview(touBtn)
payButton = UIButton()
payButton?.setTitle("Try Free", for: .normal)
payButton?.setTitleColor(UIColor.colorWithHex(hexStr: whiteColor), for: .normal)
payButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .bold)
payButton?.backgroundColor = UIColor.colorWithHex(hexStr: mColor)
payButton?.addTarget(self, action: #selector(payButtonClick), for: .touchUpInside)
self.addSubview(payButton!)
appleLabel?.snp.makeConstraints { make in appleLabel?.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-10 - safeHeight) make.top.equalTo(payButton!.snp.bottom).offset(20)
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
} }
self.addSubview(ppBtn)
ppBtn.snp.makeConstraints { make in ppBtn.snp.makeConstraints { make in
make.centerY.equalTo(appleLabel!) make.centerY.equalTo(appleLabel!)
make.left.equalToSuperview().offset(marginLR) make.left.equalToSuperview().offset(marginLR)
} }
self.addSubview(touBtn)
touBtn.snp.makeConstraints { make in touBtn.snp.makeConstraints { make in
make.centerY.equalTo(appleLabel!) make.centerY.equalTo(appleLabel!)
make.right.equalToSuperview().offset(-marginLR) make.right.equalToSuperview().offset(-marginLR)
} }
payButton = UIButton()
payButton?.setTitle("Try Free", for: .normal)
payButton?.setTitleColor(UIColor.colorWithHex(hexStr: whiteColor), for: .normal)
payButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .bold)
payButton?.backgroundColor = UIColor.colorWithHex(hexStr: mColor)
payButton?.addTarget(self, action: #selector(payButtonClick), for: .touchUpInside)
self.addSubview(payButton!)
payButton?.snp.makeConstraints({ make in
make.centerX.equalToSuperview()
make.bottom.equalTo(appleLabel!.snp.top).offset(-20)
make.width.equalToSuperview().offset(-30)
make.height.equalTo(46)
})
payButton?.layer.cornerRadius = 8 payButton?.layer.cornerRadius = 8
payButton?.layer.masksToBounds = true payButton?.layer.masksToBounds = true
...@@ -321,12 +311,19 @@ class HomePayView:UIView { ...@@ -321,12 +311,19 @@ class HomePayView:UIView {
contentView2?.backgroundColor = UIColor.colorWithHex(hexStr: "#F2F6FC") contentView2?.backgroundColor = UIColor.colorWithHex(hexStr: "#F2F6FC")
self.addSubview(contentView2!) self.addSubview(contentView2!)
contentView2?.snp.makeConstraints({ make in contentView2?.snp.makeConstraints({ make in
make.bottom.equalTo(payButton!.snp.top).offset(-12) // make.bottom.equalTo(payButton!.snp.top).offset(-12)
make.top.equalTo(forever.snp.bottom).offset(12)
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
make.width.equalToSuperview().offset(-30) make.width.equalToSuperview().offset(-30)
make.height.equalTo(60) make.height.equalTo(60)
}) })
payButton?.snp.makeConstraints({ make in
make.centerX.equalToSuperview()
// make.bottom.equalTo(appleLabel!.snp.top).offset(-20)
make.top.equalTo(contentView2!.snp.bottom).offset(12)
make.width.equalToSuperview().offset(-30)
make.height.equalTo(46)
})
contentView2?.layer.cornerRadius = 12 contentView2?.layer.cornerRadius = 12
contentView2?.layer.masksToBounds = true contentView2?.layer.masksToBounds = true
...@@ -359,16 +356,22 @@ class HomePayView:UIView { ...@@ -359,16 +356,22 @@ class HomePayView:UIView {
forever.snp.makeConstraints { make in forever.snp.makeConstraints { make in
make.left.right.equalTo(self.contentView2!) make.left.right.equalTo(self.contentView2!)
make.bottom.equalTo(self.contentView2!.snp.top).offset(-12) make.top.equalTo(yearNorBtn.snp.bottom).offset(12)
make.height.equalTo(69) make.height.equalTo(69)
} }
yearNorBtn.snp.makeConstraints { make in yearNorBtn.snp.makeConstraints { make in
make.left.right.equalTo(self.contentView2!) make.left.right.equalTo(self.contentView2!)
make.bottom.equalTo(forever.snp.top).offset(-12) make.top.equalTo(animationLabel!.snp.bottom).offset(52)
make.height.equalTo(69) make.height.equalTo(69)
} }
privavye_Label.snp.makeConstraints { make in
make.left.right.equalTo(self.contentView2!)
make.top.equalTo(ppBtn.snp.bottom).offset(15)
make.bottom.equalToSuperview().offset(-10)
}
self.layoutIfNeeded() self.layoutIfNeeded()
setIsSelect() setIsSelect()
callBack(CommonPush.change)
} }
func playAnimationWithDelay() { func playAnimationWithDelay() {
...@@ -383,10 +386,46 @@ class HomePayView:UIView { ...@@ -383,10 +386,46 @@ class HomePayView:UIView {
} }
} }
private lazy var privavye_Label: UILabel = {
let priva = UILabel()
priva.font = UIFont.systemFont(ofSize: 14)
priva.textColor = .gray
priva.text = ""
priva.numberOfLines = 0
priva.clipsToBounds = true
priva.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(labelTapped(_:)))
priva.addGestureRecognizer(tap)
addSubview(priva)
return priva
}()
@objc private func labelTapped(_ gesture: UITapGestureRecognizer) {
let location = gesture.location(in: privavye_Label)
let strs:NSString = "privacy policy"
let frssss = strs.boundingRect(with: CGSizeMake(.infinity, .infinity), options: .truncatesLastVisibleLine, attributes: [NSAttributedString.Key.font : privavye_Label.font], context: nil)
let frame1 = CGRectMake(0, privavye_Label.height-25, CGRectGetWidth(frssss), 25)
let frame2 = CGRectMake(CGRectGetWidth(frssss)+20, privavye_Label.height-25, 90, 25)
if frame1.contains(location) {
Print("点击了隐私")
// let vc:PrivacyPolicyWebViewController = PrivacyPolicyWebViewController()
// vc.hidesBottomBarWhenPushed = true
// self.navigationController?.pushViewController(vc, animated: true)
callBack(CommonPush.pp)
}else if frame2.contains(location){
Print("点击了terms")
callBack(CommonPush.tou)
// let vc:TermOfUseWebViewController = TermOfUseWebViewController()
// vc.hidesBottomBarWhenPushed = true
// self.navigationController?.pushViewController(vc, animated: true)
}
}
var product : SKProduct? { var product : SKProduct? {
didSet{ didSet{
guard let prod = product else { return } guard let prod = product else { return }
yearNorBtn.setTitles(["3 days free trial","Then \(prod.localizedPrice) per year"]) yearNorBtn.setTitles(["Then \(prod.localizedPrice) per year","3 days free trial"])
} }
} }
...@@ -417,11 +456,24 @@ class HomePayView:UIView { ...@@ -417,11 +456,24 @@ class HomePayView:UIView {
} }
@objc func ppBtnClick(btn:UIButton) { @objc func ppBtnClick(btn:UIButton) {
callBack(CommonPush.pp) btn.isSelected = !btn.isSelected
let strs:NSString = btn.isSelected ? "We offer 1-year and lifetime subscriptions. The price is clearly displayed within the application.\n\n·After the purchase confirmation, your iTunes account will be charged.\n·Unless the automatic update is turned off at least 24 hours before the end of the current cycle, the subscription will be automatically updated.\n·Your account will be renewed within 24 hours before the end of the current cycle cost.\n·You can go to the \"Account Settings\" in the iTunes store to manage your subscriptions and turn off auto renewal.\n·If provided, if you choose to use our free trial version, any unused portion during the free trial period will become invalid when you purchase a publication subscription, if applicable.\n·If you choose not to purchase the AI PhoneManager Pro version, you can continue to use it for free and enjoy PhoneManager.\n\nYour personal data is securely stored in PhoneManager, please make sure to read our \nprivacy policy and terms of use." : ""
let attribtit = NSMutableAttributedString(string:strs as String , attributes: [:])
if strs.length > 3 {
let rang = strs.range(of: "privacy policy")
attribtit.addAttributes([NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 14),NSAttributedString.Key.underlineStyle:NSUnderlineStyle.single.rawValue,.link:"appscheme://private"], range: rang)
let rang1 = strs.range(of: "terms of use")
attribtit.addAttributes([NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 14),NSAttributedString.Key.underlineStyle:NSUnderlineStyle.single.rawValue,.link:"appscheme://terms"], range: rang1)
}
privavye_Label.attributedText = attribtit
layoutIfNeeded()
callBack(CommonPush.change)
} }
@objc func touBtnClick(btn:UIButton) { @objc func touBtnClick(btn:UIButton) {
callBack(CommonPush.tou) // callBack(CommonPush.tou)
callBack(CommonPush.restore)
} }
@objc func switchValueChanged(_ sender: UISwitch) { @objc func switchValueChanged(_ sender: UISwitch) {
......
...@@ -24,9 +24,12 @@ class HomePayViewController:UIViewController { ...@@ -24,9 +24,12 @@ class HomePayViewController:UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = .green view.backgroundColor = .white
addViews() addViews()
storeKeD() storeKeD()
scroll.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
...@@ -39,11 +42,22 @@ class HomePayViewController:UIViewController { ...@@ -39,11 +42,22 @@ class HomePayViewController:UIViewController {
homePayView?.playAnimationWithDelay() homePayView?.playAnimationWithDelay()
} }
lazy var scroll: UIScrollView = {
let scroll = UIScrollView()
scroll.backgroundColor = .clear
scroll.contentInsetAdjustmentBehavior = .never
view.addSubview(scroll)
return scroll
}()
private func addViews() { private func addViews() {
homePayView = HomePayView(frame: view.bounds) homePayView = HomePayView(frame: view.bounds)
view.addSubview(homePayView!) scroll.addSubview(homePayView!)
homePayView?.snp.makeConstraints { make in
make.left.top.equalToSuperview()
make.width.equalTo(scroll.snp.width)
}
homePayView?.callBack = {[weak self] status in homePayView?.callBack = {[weak self] status in
guard let self else {return} guard let self else {return}
if let operstatus = status as? OperStatus { if let operstatus = status as? OperStatus {
...@@ -66,11 +80,16 @@ class HomePayViewController:UIViewController { ...@@ -66,11 +80,16 @@ class HomePayViewController:UIViewController {
self.payTouch() self.payTouch()
break break
case .swit: case .swit:
break break
case .restore: case .restore:
self.restoreClick() self.restoreClick()
break break
case .change:
DispatchQueue.main.async {
let contentSize = CGRectGetHeight(self.homePayView?.frame ?? CGRect())
self.scroll.contentSize = CGSizeMake(0, contentSize)
}
break
} }
} }
} }
......
...@@ -25,6 +25,7 @@ enum CommonPush { ...@@ -25,6 +25,7 @@ enum CommonPush {
case swit case swit
case pay case pay
case restore case restore
case change
} }
enum tabbarType { enum tabbarType {
......
...@@ -56,3 +56,47 @@ extension UILabel { ...@@ -56,3 +56,47 @@ extension UILabel {
self.width = width self.width = width
} }
} }
extension UILabel {
func isTapLocationInTextRange(_ gesture: UITapGestureRecognizer, range: NSRange) -> Bool {
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: .zero)
let textStorage = NSTextStorage(attributedString: self.attributedText ?? NSAttributedString())
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
textContainer.lineFragmentPadding = 0
textContainer.lineBreakMode = self.lineBreakMode
textContainer.maximumNumberOfLines = self.numberOfLines
textContainer.size = self.bounds.size
let location = gesture.location(in: self)
let textBoundingBox = layoutManager.usedRect(for: textContainer)
let alignmentOffset = self.alignmentOffsetForText(in: textBoundingBox)
let touchLocation = CGPoint(
x: (location.x - alignmentOffset),
y: (location.y - textBoundingBox.minY)
)
let index = layoutManager.characterIndex(
for: touchLocation,
in: textContainer,
fractionOfDistanceBetweenInsertionPoints: nil
)
return NSLocationInRange(index, range)
}
private func alignmentOffsetForText(in rect: CGRect) -> CGFloat {
switch self.textAlignment {
case .left, .natural, .justified:
return 0
case .center:
return (self.bounds.width - rect.width) / 2
case .right:
return self.bounds.width - rect.width
@unknown default:
return 0
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment