0
Рабочий код слайдов слева от окна и сдвиньте его вправо, чтобы показать его полностью. Поскольку я изучаю быстро, я был бы благодарен за ваши комментарии, чтобы улучшить его. Я включил некоторые факторинги, которые не работали.Многозначный распознаватель одного взгляда
Рабочий код:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myLabel: UILabel!
@IBOutlet var parentView: UIView!
var swipGestureRight: UISwipeGestureRecognizer!
var swipGestureLeft: UISwipeGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myLabel.userInteractionEnabled = true
swipGestureLeft = UISwipeGestureRecognizer(target: self, action: Selector("swipViewLeft:"))
swipGestureLeft.direction = .Left
parentView.gestureRecognizers = [swipGestureLeft]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func swipViewLeft(gesture: UISwipeGestureRecognizer){
UIView.animateWithDuration(0.3, animations: {self.myLabel.center.x -= (self.myLabel.bounds.width)}, completion: nil)
swipGestureRight = UISwipeGestureRecognizer(target: self, action: Selector("swipViewRight:"))
swipGestureRight.direction = .Right
parentView.gestureRecognizers = [swipGestureRight]
}
func swipViewRight(gesture: UISwipeGestureRecognizer){
UIView.animateWithDuration(0.3, animations: {self.myLabel.center.x += (self.myLabel.bounds.width)}, completion: nil)
swipGestureLeft = UISwipeGestureRecognizer(target: self, action: Selector("swipViewLeft:"))
swipGestureLeft.direction = .Left
parentView.gestureRecognizers = [swipGestureLeft]
}
}
Ошибка при попытке улучшить:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myLabel: UILabel!
@IBOutlet var parentView: UIView!
var swipGestureRecognizer: UISwipeGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myLabel.userInteractionEnabled = true
swipGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipping:"))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func swipping(gestureRecognizer: UISwipeGestureRecognizer){
if gestureRecognizer.direction == .Left {
parentView.gestureRecognizers = [gestureRecognizer]
UIView.animateWithDuration(0.3, animations: {self.myLabel.center.x -= (self.myLabel.bounds.width)}, completion: nil)
} else {
UIView.animateWithDuration(0.3, animations: {self.myLabel.center.x += (self.myLabel.bounds.width)}, completion: nil)
}
}
}
Если я переведу его, чтобы быть последней строкой в viewDidLoad(), левый салфетка не срабатывает, что должно быть сделано первым, поскольку я пытаюсь имитировать панель навигации слайда;) –