我正在尝试快速制作一个项目并且对语言不熟悉。
我试图让UIView显示并消失,然后向上滑动并在屏幕上向下滑动。我目前正在使用结构来存储视图的实例,以便能够使用swipeUp()和swipeDown()方法进行更改。
当我尝试访问this.view.bounds.height时,它告诉我"实例成员视图不能用于类型SecondViewController"
以下是我的代码
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
class SecondViewController: UIViewController {
let label = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
let swipeUp = UISwipeGestureRecognizer(target: self, action: "swipeUp")
swipeUp.direction = UISwipeGestureRecognizerDirection.up
self.view.addGestureRecognizer(swipeUp)
let swipeDown = UISwipeGestureRecognizer(target: self, action: "swipeDown")
swipeDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeDown)
}
struct myVars{
let v = MyCustomView(frame: CGRect(x: 0, y: this.view.bounds.height / 2, width: this.view.bounds.width, height: self.view.bounds.height / 2))
}
func swipeUp(){
if myVars.v.isDescendantOfView(self) {
myVars.v.isHidden = false
}
else {
self.view.addSubview(myVars.v)
}
}
func swipeDown(){
myVars.v.isHidden = true
}
}
您能告诉我我的代码有什么问题吗?或者让我知道是否有更好的方法可以完成这项工作?
答案 0 :(得分:0)
只需选中替换您的代码使用以下代码即可。 取代#selector(ViewController.swipeUp)放置viewController的名称
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeUp))
swipeUp.direction = UISwipeGestureRecognizerDirection.up
self.view.addGestureRecognizer(swipeUp)
let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.swipeDown))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeDown)