我有一个页面,从数据库检索数据以显示当前信息或之前或之后的信息。
它是这样的:
if Status = 1 it shows the current
Status = 2 it shows previous
Status = 0 it shows next
到目前为止,我所做的是显示当前的数据并且它完美地展示出来了。现在我需要添加一个功能,当用户向右滑动屏幕时,会显示下一张图片,向左滑动时则会显示上一张。
有任何想法或指引从何开始吗?
谢谢!
我有一个页面,从数据库检索数据以显示当前信息或之前或之后的信息。
它是这样的:
if Status = 1 it shows the current
Status = 2 it shows previous
Status = 0 it shows next
到目前为止,我所做的是显示当前的数据并且它完美地展示出来了。现在我需要添加一个功能,当用户向右滑动屏幕时,会显示下一张图片,向左滑动时则会显示上一张。
有任何想法或指引从何开始吗?
谢谢!
override func viewDidLoad()
{
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
}
func respondToSwipeGesture(gesture: UIGestureRecognizer)
{
if let swipeGesture = gesture as? UISwipeGestureRecognizer
{
switch swipeGesture.direction
{
case UISwipeGestureRecognizerDirection.Right:
//write your logic for right swipe
print("Swiped right")
case UISwipeGestureRecognizerDirection.Left:
//write your logic for left swipe
print("Swiped left")
default:
break
}
}
}
swipeRight.direction = [UISwipeGestureRecognizerDirection.left, UISwipeGestureRecognizerDirection.right]
。 - leafcutterclass WelcomeController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet var backgroundView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Create left swipe gesture recognizer
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
leftSwipe.direction = .left
backgroundView.addGestureRecognizer(leftSwipe)
// Create right swipe gesture recognizer
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
rightSwipe.direction = .right
backgroundView.addGestureRecognizer(rightSwipe)
}
@objc func handleSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
if gestureRecognizer.direction == .left {
// Handle left swipe
} else if gestureRecognizer.direction == .right {
// Handle right swipe
}
}
}
// Use ChatGPT