Use my Swipe gesture function on multiple UILabels swift - ios

Im a newbie, ive managed to find and adapt code so that when i swipe a label, the value of that label changes. Now my func only relates to one particular label, but i want to make multiple labels have the exact same function, its a statistic taking label, how do i modify/apply the func to many different labels?
Here is my code:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var counterLabel: UILabel!
#IBOutlet weak var kickLabel: UILabel!
var counter = 0
var swipeGesture = UISwipeGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
let direction: [UISwipeGestureRecognizerDirection] = [.up, .down, .left, .right]
for dir in direction{
swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(self.counterLabel(_:)))
counterLabel.addGestureRecognizer(swipeGesture)
swipeGesture.direction = dir
counterLabel.isUserInteractionEnabled = true
counterLabel.isMultipleTouchEnabled = true
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#objc func counterLabel(_ sender:UISwipeGestureRecognizer){
UIView.animate(withDuration: 1.0) {
if sender.direction == .right{
print("Swiped Right")
self.counter += 1
print(self.counter)
self.counterLabel.text = String(self.counter)
}else if sender.direction == .left{
print("Swiped Left")
print(self.counter)
self.counter -= 1
self.counterLabel.text = String(self.counter)
}else if sender.direction == .up{
print("Swiped Up")
self.counter += 5
self.counterLabel.text = String(self.counter)
}else if sender.direction == .down{
print("Swiped Down")
self.counter = 0
self.counterLabel.text = String(self.counter)
}
}
}
}

UISwipeGestureRecognizer has the view the gesture is applied to. Cast this to a UILabel.
(You might also want to check the gesture state for better performance.)
class ViewController: UIViewController {
#IBOutlet weak var label1: UILabel!
#IBOutlet weak var label2: UILabel!
var counters: [UILabel: Int] = [:]
override func viewDidLoad() {
super.viewDidLoad()
for label: UILabel in [label1, label2] {
counters[label] = 0
for direction: UISwipeGestureRecognizerDirection in [.up, .down, .left, .right] {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(didSwipe(_:)))
swipeGesture.direction = direction
label.addGestureRecognizer(swipeGesture)
}
}
}
#objc func didSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
guard gestureRecognizer.state == .recognized else { return }
guard let label = gestureRecognizer.view as? UILabel else { return }
debugPrint("\(gestureRecognizer.direction)")
switch gestureRecognizer.direction {
case .up:
counters[label] = counters[label] + 1
label.text = "Up"
case .down:
label.text = "Down"
case .left:
label.text = "Left"
case .right:
label.text = "Right"
default:
label.text = "???"
}
}
}

Related

How to Swipe UIView on Button Action in all four directions

I have Two UIButtons on Right and Left and a UIView At Middle of the button..
I have to swipe ContainerView with some animation on UIButton click..
If user tap on right button ContainerView swipe to .right direction....If user tap on Left button ContainerView swipe to .left direction..
I have not found it anyWhere....Need help with full coding part
I have done this on my view
override func viewDidAppear(_ animated: Bool) {
leftSwipe()
rightSwipe()
}
//MARK:Left Swipe Function
func leftSwipe()
{
let swipeLeft = UISwipeGestureRecognizer()
swipeLeft.direction = .left
self.insideContainerViewSecond.addGestureRecognizer(swipeLeft)
swipeLeft.addTarget(self, action: #selector(swipe(sender:)))
}
//MARK:Right Swipe Function
func rightSwipe()
{
let swipeRight = UISwipeGestureRecognizer()
swipeRight.direction = .right
self.insideContainerViewSecond.addGestureRecognizer(swipeRight)
swipeRight.addTarget(self, action: #selector(swipe(sender:)))
}
//MARK: Swipe Function
#objc func swipe(sender: UISwipeGestureRecognizer)
{
switch sender.direction
{
case .left:
print("swiped left")
case .right:
print("swiped right")
default:
print("no action")
}
}
In this image I have a UIView and two button right and left..When I swipe on my UIView It swipe Left and right without animation.....But I need to swipe my UIView on right or Left button action with flip animation
We have CATransition Classes with iOS. You should use this. Or you should constraint animation. Maybe this repo is helped you for first trick.
https://github.com/barankaraoguzzz/FastOnBoarding/blob/master/FOView/Classes/FOAnimation.swift
if this answer doesn't be true for this question. Come again :)
You have a couple different questions...
How to "simulate" a swipe-gesture on a button tap?
You could do this different ways, such as creating a showNextImage() function, and then call it on swipe-left or on right-button-tap.
Or, you could do something like this, where you create a temporary swipe gesture recognizer and pass it to your recognizer function:
#objc func leftButtonTap(_ sender: UIButton)
{
// create a right-swipe-gesture
let sgr = UISwipeGestureRecognizer()
sgr.direction = .right
self.swipe(sender: sgr)
}
#objc func rightButtonTap(_ sender: UIButton)
{
// create a left-swipe-gesture
let sgr = UISwipeGestureRecognizer()
sgr.direction = .left
self.swipe(sender: sgr)
}
You said on swipe (or button tap), you want to use flip animation to show the next (or previous) image?
You can do this by adding two image views to your "container" view. Set one view hidden. When you want to "show the next image," set the .image property of the hidden imageView and then use UIView.transition(...) to flip from the visible imageView to the hidden imageView:
private func flipMe(_ direction: UIView.AnimationOptions) -> Void {
// fromView is the one that is NOT hidden
let fromView = imgViewB.isHidden ? imgViewA : imgViewB
// toView is the one that IS hidden
let toView = imgViewB.isHidden ? imgViewB : imgViewA
UIView.transition(from: fromView,
to: toView,
duration: 0.5,
options: [direction, .showHideTransitionViews],
completion: { b in
// if we want to do something on completion
})
}
Here is a simple example that you can run and see what happens. No #IBOutlet or #IBAction connections, so you don't need any Storyboard setup:
FlipView custom view subclass:
class FlipView: UIView {
// set image names from controller
var imageNames: [String] = [] {
didSet {
if let img = UIImage(named: imageNames[0]) {
imgViewB.image = img
} else {
imgViewB.image = testImage()
}
}
}
// index counter
private var idx: Int = 0
// two image views
private let imgViewA: UIImageView = UIImageView()
private let imgViewB: UIImageView = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}
func commonInit() -> Void {
// add both image views
// with light-gray backgrounds
// constraining all 4 sides to self
[imgViewA, imgViewB].forEach { v in
v.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
addSubview(v)
v.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
v.topAnchor.constraint(equalTo: topAnchor),
v.leadingAnchor.constraint(equalTo: leadingAnchor),
v.trailingAnchor.constraint(equalTo: trailingAnchor),
v.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}
// start with one of the image views hidden
imgViewA.isHidden = true
}
private func flipMe(_ direction: UIView.AnimationOptions) -> Void {
// fromView is the one that is NOT hidden
let fromView = imgViewB.isHidden ? imgViewA : imgViewB
// toView is the one that IS hidden
let toView = imgViewB.isHidden ? imgViewB : imgViewA
UIView.transition(from: fromView,
to: toView,
duration: 0.5,
options: [direction, .showHideTransitionViews],
completion: { b in
// if we want to do something on completion
})
}
func flipToPrevious() -> Void {
// don't try to flip past the first image
if idx == 0 {
return
}
// decrement the index
idx -= 1
let hiddenImageView = imgViewA.isHidden ? imgViewA : imgViewB
// get the previous image
if let img = UIImage(named: imageNames[idx]) {
hiddenImageView.image = img
} else {
hiddenImageView.image = testImage()
}
// flip it from left
flipMe(.transitionFlipFromLeft)
}
func flipToNext() -> Void {
// don't try to flip past the last image
if idx == imageNames.count - 1 {
return
}
// increment the index
idx += 1
let hiddenImageView = imgViewA.isHidden ? imgViewA : imgViewB
// get the next image
if let img = UIImage(named: imageNames[idx]) {
hiddenImageView.image = img
} else {
hiddenImageView.image = testImage()
}
// flip it from right
flipMe(.transitionFlipFromRight)
}
// get a numbered system image if the named image
// cannot be loaded from assets
private func testImage() -> UIImage {
let colors: [UIColor] = [
.systemRed, .systemGreen, .systemBlue,
.systemYellow, .systemTeal, .systemPurple,
]
guard let img = UIImage(systemName: "\(idx+1).circle") else {
// that should not fail, but in case it does
return UIImage()
}
return img.withTintColor(colors[idx % colors.count], renderingMode: .alwaysOriginal)
}
}
ViewController example ViewController class:
class ViewController: UIViewController {
let insideContainerViewSecond: FlipView = FlipView()
override func viewDidLoad() {
super.viewDidLoad()
// respect safe area
let g = view.safeAreaLayoutGuide
// create left and right buttons
let leftButton = UIButton()
leftButton.translatesAutoresizingMaskIntoConstraints = false
let leftImg = UIImage(systemName: "chevron.left.circle.fill")
leftButton.setImage(leftImg, for: [])
leftButton.addTarget(self, action: #selector(leftButtonTap(_:)), for: .touchUpInside)
let rightButton = UIButton()
rightButton.translatesAutoresizingMaskIntoConstraints = false
let rightImg = UIImage(systemName: "chevron.right.circle.fill")
rightButton.setImage(rightImg, for: [])
rightButton.addTarget(self, action: #selector(rightButtonTap(_:)), for: .touchUpInside)
insideContainerViewSecond.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(insideContainerViewSecond)
view.addSubview(leftButton)
view.addSubview(rightButton)
NSLayoutConstraint.activate([
insideContainerViewSecond.topAnchor.constraint(equalTo: g.topAnchor, constant: 80.0),
insideContainerViewSecond.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 80.0),
insideContainerViewSecond.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -80.0),
insideContainerViewSecond.heightAnchor.constraint(equalTo: insideContainerViewSecond.widthAnchor, multiplier: 0.5),
leftButton.centerYAnchor.constraint(equalTo: insideContainerViewSecond.topAnchor),
leftButton.centerXAnchor.constraint(equalTo: insideContainerViewSecond.leadingAnchor),
rightButton.centerYAnchor.constraint(equalTo: insideContainerViewSecond.topAnchor),
rightButton.centerXAnchor.constraint(equalTo: insideContainerViewSecond.trailingAnchor),
])
// your array of image names
let imageNames: [String] = [
"pic1", "pic2", "pic3", "pic4", "pic5", "pic6",
]
insideContainerViewSecond.imageNames = imageNames
leftSwipe()
rightSwipe()
}
//MARK:Left Swipe Function
func leftSwipe()
{
let swipeLeft = UISwipeGestureRecognizer()
swipeLeft.direction = .left
self.insideContainerViewSecond.addGestureRecognizer(swipeLeft)
swipeLeft.addTarget(self, action: #selector(swipe(sender:)))
}
//MARK:Right Swipe Function
func rightSwipe()
{
let swipeRight = UISwipeGestureRecognizer()
swipeRight.direction = .right
self.insideContainerViewSecond.addGestureRecognizer(swipeRight)
swipeRight.addTarget(self, action: #selector(swipe(sender:)))
}
//MARK: Swipe Function
#objc func swipe(sender: UISwipeGestureRecognizer)
{
switch sender.direction
{
case .left:
print("swiped left")
self.insideContainerViewSecond.flipToNext()
case .right:
print("swiped right")
self.insideContainerViewSecond.flipToPrevious()
default:
print("no action")
}
}
#objc func leftButtonTap(_ sender: UIButton)
{
// create a right-swipe-gesture
let sgr = UISwipeGestureRecognizer()
sgr.direction = .right
self.swipe(sender: sgr)
}
#objc func rightButtonTap(_ sender: UIButton)
{
// create a left-swipe-gesture
let sgr = UISwipeGestureRecognizer()
sgr.direction = .left
self.swipe(sender: sgr)
}
}

UIPangestureRecognizer - One Image Interects with Another

I am stumped on how to get a certain behavior out of my experiment with UIPanGestureRecognizer.
When a user taps and holds an image, and it then intersects with another image, a behavior is triggered. In this case, the behavior is that the opacity of the green or red image goes to 100%.
Once a user continues dragging the image around the screen, and breaks the intersect with either the green or red image, I'd like its opacity to return to 50%. My control flow is getting ugly. I keep tweaking it, but am stumped to find the logic that gets me what I want.
visual
#objc func handlePan(sender: UIPanGestureRecognizer) {
let imageOneView = sender.view!
let translation = sender.translation(in: view)
switch sender.state {
case .began, .changed:
imageOneView.center = CGPoint(x: imageOneView.center.x + translation.x, y: imageOne.center.y + translation.y)
sender.setTranslation(CGPoint.zero, in: view)
view.bringSubviewToFront(imageOne)
if imageOne.frame.intersects(winImage.frame) {
winImage.alpha = 1
} else {
if imageOne.frame.intersects(loseImage.frame) {
loseImage.alpha = 1
winImage.alpha = 0.5
} else {
return
}
}
case .ended:
if imageOne.frame.intersects(winImage.frame) {
UIView.animate(withDuration: 0.3, animations: {
self.imageOne.alpha = 0.0
})
performSegue(withIdentifier: "winnerDetailView", sender: self)
} else {
if imageOne.frame.intersects(loseImage.frame) {
UIView.animate(withDuration: 0.3, animations: {
self.imageOne.alpha = 0.0
})
navigationItem.rightBarButtonItem?.isEnabled = true
loseImage.alpha = 0.5
} else {
UIView.animate(withDuration: 0.3) {
self.imageOne.frame.origin = self.imageOneOrgin
}
}
}
default:
break
}
}
And additional code: https://github.com/ericmseitz/imageWar
Thanks.
Couple things...
Control flow looks good.
To get the "win" and "lost" alpha reset, set them both to 0.5 on entry to handlePan(). If intersection is detected, set the appropriate one to 1.0. It won't update until the UI updates, which won't happen inside this function.
If you have your draggable views embedded in stack views (as you have in your GitHub repo), you won't be able to bring them in front of each other.
Also, if you have your draggable views embedded in stack views (or other views) make sure to convert the frame to the main view's coordinate space.
Here is modified code, based on what you posted in your question and the layout (stack view embedded) in your repo:
class ViewController: UIViewController {
// IBOutlets
#IBOutlet weak var winImage: UIImageView!
#IBOutlet weak var loseImage: UIImageView!
#IBOutlet weak var imageOne: UIImageView!
#IBOutlet weak var imageTwo: UIImageView!
#IBOutlet weak var imageThree: UIImageView!
#IBOutlet weak var imageFour: UIImageView!
// Constants and Variables
var currentImageCenter = CGPoint.zero
override func viewDidLoad() {
super.viewDidLoad()
[imageOne, imageTwo, imageThree, imageFour].forEach {
let p = UIPanGestureRecognizer(target: self, action: #selector(handlePan(sender:)))
$0?.addGestureRecognizer(p)
}
winImage.alpha = 0.5
loseImage.alpha = 0.5
}
#objc func handlePan(sender: UIPanGestureRecognizer) {
guard let imageOneView = sender.view else { return }
let translation = sender.translation(in: view)
// set alpha for both to 0.5
// if either is intersected, it will be set to 1.0
winImage.alpha = 0.5
loseImage.alpha = 0.5
switch sender.state {
case .began:
// track center of drag-view so we can return if needed
currentImageCenter = imageOneView.center
case .changed:
imageOneView.center = CGPoint(x: imageOneView.center.x + translation.x, y: imageOneView.center.y + translation.y)
sender.setTranslation(CGPoint.zero, in: view)
// convert drag-view frame to view coordinate space
guard let r = view.getConvertedFrame(fromSubview: imageOneView) else { return }
view.bringSubviewToFront(imageOneView)
if r.intersects(winImage.frame) {
winImage.alpha = 1
} else {
if r.intersects(loseImage.frame) {
loseImage.alpha = 1
} else {
return
}
}
case .ended:
// convert drag-view frame to view coordinate space
guard let r = view.getConvertedFrame(fromSubview: imageOneView) else { return }
if r.intersects(winImage.frame) {
UIView.animate(withDuration: 0.3, animations: {
imageOneView.alpha = 0.0
})
//performSegue(withIdentifier: "winnerDetailView", sender: self)
} else {
if r.intersects(loseImage.frame) {
UIView.animate(withDuration: 0.3, animations: {
imageOneView.alpha = 0.0
})
navigationItem.rightBarButtonItem?.isEnabled = true
} else {
UIView.animate(withDuration: 0.3) {
imageOneView.center = self.currentImageCenter
}
}
}
default:
break
}
}
}
Note: the above needs this UIView extension to convert the frame coordinates:
// from Answer on StackOverflow: https://stackoverflow.com/a/57261226/6257435
extension UIView {
// there can be other views between `subview` and `self`
func getConvertedFrame(fromSubview subview: UIView) -> CGRect? {
// check if `subview` is a subview of self
guard subview.isDescendant(of: self) else {
return nil
}
var frame = subview.frame
if subview.superview == nil {
return frame
}
var superview = subview.superview
while superview != self {
frame = superview!.convert(frame, to: superview!.superview)
if superview!.superview == nil {
break
} else {
superview = superview!.superview
}
}
return superview!.convert(frame, to: self)
}
}

Individual Labels update value when swiped

Ive got my swipe functionality working now on individual labels due to some great help! Now I just need each of those labels to update individually when swiped, so each label has its own seperate counter and doesnt effect the other ones.
heres my code:
import UIKit
class ViewController: UIViewController {
var counter = 0
#IBOutlet weak var label1: UILabel!
#IBOutlet weak var label2: UILabel!
#IBOutlet weak var label3: UILabel!
var counters: [UILabel: Int] = [:]
override func viewDidLoad() {
super.viewDidLoad()
for label: UILabel in [label1, label2, label3] {
counters[label] = 0
for direction: UISwipeGestureRecognizerDirection in [.up, .down, .left, .right] {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(didSwipe(_:)))
swipeGesture.direction = direction
label.addGestureRecognizer(swipeGesture)
label.isUserInteractionEnabled = true
label.isMultipleTouchEnabled = true
}
}
}
#objc func didSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
guard let label = gestureRecognizer.view as? UILabel else { return }
debugPrint("\(gestureRecognizer.direction)")
switch gestureRecognizer.direction {
case .up:
counters[label] = counters[label]! + 5
print(counters)
case .down:
counters[label] = 0
print(counters)
case .left:
counters[label] = counters[label]! - 1
print(counters)
case .right:
counters[label] = counters[label]! + 1
print(counters)
default:
label.text = "0"
}
}
}
You need to call
label.text = "\(counters[label]!)"
At the end of your switch statement. This should work.
I see how, set the label of the text at the end of the gesture.
label.text = “(counters[label]!)”
For example,
#objc func didSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
guard let label = gestureRecognizer.view as? UILabel else { return }
debugPrint("\(gestureRecognizer.direction)")
switch gestureRecognizer.direction {
case .up:
counters[label] = counters[label]! + 5
print(counters)
case .down:
counters[label] = 0
print(counters)
case .left:
counters[label] = counters[label]! - 1
print(counters)
case .right:
counters[label] = counters[label]! + 1
print(counters)
default:
counters[label] = 0
}
label.text = “\(counters[label]!)”
}

How to drag and drop an image on delete icon to delete the image?

Hey guys I have just created a sample image view that can be dragged inside the view.
My Question is how to delete the image when it is dragged and placed in the delete icon?
Can anyone help with swift code
Herewith I have attached my sample program code below:
import UIKit
class ViewController: UIViewController, UIGestureRecognizerDelegate {
var Lastscale : CGFloat = 1.0
#IBOutlet weak var imgView: UIImageView!
#IBOutlet weak var deleteIcon: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(ViewController.handlePan(recognizer:)))
panGestureRecognizer.delegate = self
imgView.addGestureRecognizer(panGestureRecognizer)
imgView.isUserInteractionEnabled = true
}
#objc func handlePan(recognizer: UIPanGestureRecognizer) {
let gview = recognizer.view
if recognizer.state == .began || recognizer.state == .changed {
let translation = recognizer.translation(in: gview?.superview)
gview?.center = CGPoint(x: (gview?.center.x)! + translation.x, y: (gview?.center.y)! + translation.y)
recognizer.setTranslation(CGPoint.zero, in: gview?.superview)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Firstly, it's cleaner to use a switch statement to check for recognizer states. Also I think in this case you'd like to set the transform of the layer while the recognizer translation is changing, in this way you retain the initial frame of the view and always can animate back by setting the transform to its identity. Then if the rectangles of the button and image view layer intersect, hide the imageView, else move back. Like this:
#objc func handlePan(recognizer: UIPanGestureRecognizer) {
let gview = recognizer.view
let translation = recognizer.translation(in: gview?.superview)
switch recognizer.state {
case .began, .changed:
imgView.layer.transform = CATransform3DMakeTranslation(translation.x, translation.y, 0)
// OR
// imgView.transform = CGAffineTransform(translationX: translation.x, y: translation.y)
case .ended:
if deleteIcon.frame.intersects(imgView.layer.frame) {
animateDelete()
} else {
moveBack()
}
default:
moveBack()
}
}
func animateDelete() {
UIView.animate(withDuration: 0.3, animations: {
self.imgView.alpha = 0
}) { _ in
self.imgView.isHidden = true
}
}
func moveBack() {
UIView.animate(withDuration: 0.3) {
self.imgView.transform = CGAffineTransform.identity
}
}

How do I make a UIImageView "flickable"?

I have a UIImageView that the user can move around, but I want the user to kind of swipe it or "flick" it in a direction and it will fly off in the direction the user swiped/flicked it.
Here is the code for the UIImageView:
#IBOutlet var imageView: UIImageView!
var location = CGPoint(x: 0, y: 0)
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch! = touches.first as! UITouch
location = touch.locationInView(self.view)
imageView.center = location
}
You need to use UIKit Dynamics.
Here is a tutorial:
http://www.raywenderlich.com/71828/uikit-dynamics-tutorial-tossing-views
U can use UISwipeGestureRecognizer to move
Here is a code
#IBOutlet var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
var rightSwipe = UISwipeGestureRecognizer(target: self, action: "HandleSwipeGesture:")
var leftswipe = UISwipeGestureRecognizer(target: self, action: "HandleSwipeGesture:")
rightSwipe.direction = .Right
leftswipe.direction = .Left
imageView.addGestureRecognizer(rightSwipe)
imageView.addGestureRecognizer(leftswipe)
}
func HandleSwipeGesture(sender:UISwipeGestureRecognizer){
if(sender.direction == .Right){
// do other task
}
else{
if(sender.direction == .Left){
// do other task
}
}
}
for swipe you can try it.
varysLeftSwipe=UISwipeGestureRecognizer(target:self,action:Selector("handleSwipes:"))
var ysRightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
ysLeftSwipe.direction = UISwipeGestureRecognizerDirection.Left
ysRightSwipe.direction = UISwipeGestureRecognizerDirection.Right
ysSlideImageView.addGestureRecognizer(ysLeftSwipe)
ysSlideImageView.addGestureRecognizer(ysRightSwipe)
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Left) {
self.showNextData()
}
if (sender.direction == .Right) {
self.showPreviousData()
}
}
func showPreviousData(){
if index > 0 {
index = index - 1
ysForWordButton.hidden = false
if index == 0{
ysBackWordButton.hidden = true
}
}
else{
ysBackWordButton.hidden = true
ysForWordButton.hidden = false
}
ysSlideImageView.image = UIImage(data: NSData(contentsOfURL: NSURL(string: ysCollectionImgArray.objectAtIndex(index) as NSString)!)!)
}
func showNextData(){
if index < ysCollectionImgArray.count - 1 {
index = index + 1
ysBackWordButton.hidden = false
if ysCollectionImgArray.count - 1 == index {
ysForWordButton.hidden = true
}
}
else{
ysForWordButton.hidden = true
ysBackWordButton.hidden = false
// index = 0
}
ysSlideImageView.image = UIImage(data: NSData(contentsOfURL: NSURL(string: ysCollectionImgArray.objectAtIndex(index) as NSString)!)!)
}

Resources