新版ios12下,苹果手机运行某项目,提示我必须用Xcode10来编译。
我就安装了Xcode10,但编译得到一个错误:'self' used before 'super.init' call。急着上线!注:原代码在iOS11下正常编译通过。
zhubajie网另有500元相送,请看:https://task.zbj.com/178666556044099584调用方的成员函数如下:
------------------------
static func showPrize(imgUrl:String?,buttonActionBlock:(()->())?) {
guard let _imgUrl = imgUrl else { return }
KingfisherManager.shared.retrieveImage(with: URL.init(string: _imgUrl)!, options: nil, progressBlock: nil) { (image, error, cacheType, url) in
guard let _image = image else { return }
let backgroundView = UIView(frame: UIScreen.main.bounds)
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
backgroundView.alpha = 0
UIApplication.win.addSubview(backgroundView)
let htw_scale = _image.size.height / _image.size.width
let width = UIScreen.main.ScreenWidth - 48 * 2
let height = width * htw_scale
let view = AlertView(frame: .init(x: 48, y: ( UIScreen.main.ScreenHeight - height ) / 2.0, width:width , height:height))
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 4
view.layer.masksToBounds = true
let poster = UIImageView.init(image: _image)
view.addSubview(poster)
poster.contentMode = .scaleToFill
poster.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
view.alpha = 0
view.addGestureRecognizer(CLUITapGestureRecognizer.init(block: {[weak view] in
buttonActionBlock!()
view?.isHidden = true
UIView.animate(withDuration: 0.2, animations: {
backgroundView.alpha = 0
}, completion: { (b) in
backgroundView.removeFromSuperview()
view?.removeFromSuperview()
})
}))
UIApplication.win.addSubview(view)
view.transform = CGAffineTransform.init(scaleX: 0, y: 0)
UIView.animate(withDuration: 0.3) {
view.transform = CGAffineTransform.init(scaleX: 1, y: 1)
backgroundView.alpha = 1
view.alpha = 1
}
}
}
被调方的整个文件如下:
-----------------------------
import UIKit
class CLUITapGestureRecognizer: UITapGestureRecognizer {
public typealias _ActionBlock = ()->()
private var _block:_ActionBlock?
deinit {
CLLog(message: "CLUITapGestureRecognizer dealloc")
}
init(block:@escaping(_ActionBlock)) {
self._block = block
super.init(target:self, action: #selector(CLUITapGestureRecognizer._action))
}
@objc private func _action(){
_block?()
}
}
我就安装了Xcode10,但编译得到一个错误:'self' used before 'super.init' call。急着上线!注:原代码在iOS11下正常编译通过。
zhubajie网另有500元相送,请看:https://task.zbj.com/178666556044099584调用方的成员函数如下:
------------------------
static func showPrize(imgUrl:String?,buttonActionBlock:(()->())?) {
guard let _imgUrl = imgUrl else { return }
KingfisherManager.shared.retrieveImage(with: URL.init(string: _imgUrl)!, options: nil, progressBlock: nil) { (image, error, cacheType, url) in
guard let _image = image else { return }
let backgroundView = UIView(frame: UIScreen.main.bounds)
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
backgroundView.alpha = 0
UIApplication.win.addSubview(backgroundView)
let htw_scale = _image.size.height / _image.size.width
let width = UIScreen.main.ScreenWidth - 48 * 2
let height = width * htw_scale
let view = AlertView(frame: .init(x: 48, y: ( UIScreen.main.ScreenHeight - height ) / 2.0, width:width , height:height))
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 4
view.layer.masksToBounds = true
let poster = UIImageView.init(image: _image)
view.addSubview(poster)
poster.contentMode = .scaleToFill
poster.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
view.alpha = 0
view.addGestureRecognizer(CLUITapGestureRecognizer.init(block: {[weak view] in
buttonActionBlock!()
view?.isHidden = true
UIView.animate(withDuration: 0.2, animations: {
backgroundView.alpha = 0
}, completion: { (b) in
backgroundView.removeFromSuperview()
view?.removeFromSuperview()
})
}))
UIApplication.win.addSubview(view)
view.transform = CGAffineTransform.init(scaleX: 0, y: 0)
UIView.animate(withDuration: 0.3) {
view.transform = CGAffineTransform.init(scaleX: 1, y: 1)
backgroundView.alpha = 1
view.alpha = 1
}
}
}
被调方的整个文件如下:
-----------------------------
import UIKit
class CLUITapGestureRecognizer: UITapGestureRecognizer {
public typealias _ActionBlock = ()->()
private var _block:_ActionBlock?
deinit {
CLLog(message: "CLUITapGestureRecognizer dealloc")
}
init(block:@escaping(_ActionBlock)) {
self._block = block
super.init(target:self, action: #selector(CLUITapGestureRecognizer._action))
}
@objc private func _action(){
_block?()
}
}
解决方案 »
- IOS如何设置一个类为全局变量,供另外两个类一起调用
- Xcode4.2建立Single View Project可不可以实现类似导航工程的作用?
- 最近做了一个开源的Objective-C/Cocoa的库,包括base64, oauth 1.0/2.0和一些demo
- xcode中如何放置项目的文档
- mac系统,如何编译运行.m文件
- xcode怎么查看类关系。。。
- 求XCODE5.1,IOS7.1帶證書真機調試詳細步驟
- 开源我的炫酷动画世界杯APP.
- 两个TableView做同步选中行时,选中行高亮效果延迟的问题
- Xcode8.3,打包时候出现一个警告,求大神
- app退出之后自动重启
- IOS怎么修改照片的名字
self因该是不能作为super.init的参数的,这个在哪个版本都编译不过去
self._block = block