STEP-1 : Add 'Image View' to Main.Storyboard on whole screen
STEP-2 : Add 2 or more image to Assets.xcassets folder.
STEP-3 : ViewController.swift
//
// ViewController.swift
// ShakeGesture
//
// Created by Admin on 27/06/17.
// Copyright © 2017 Admin. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
let images = ["image01", "image02", "image03"]
var currentimage = 0;
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
if event?.subtype == UIEventSubtype.motionShake
{
print("Shaking")
imageView.image = UIImage(named: images[currentimage]+".jpg")
if (currentimage == images.count-1)
{
currentimage = 0
}else
{
currentimage += 1
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
No comments:
Post a Comment