如何将图像切换到另一个图像?

时间:2016-07-27 06:01:04

标签: ios iphone swift uiimage

当我上下移动设备时,如何将图像切换到另一个图像?如果是复杂的解释可以有人请链接我一篇文章?我试过了http://nshipster.com/cmdevicemotion/,但它没有用。我找不到任何其他东西。你能帮忙吗?

我试过

//
//  ViewController.swift
//  cheesetest
//
//  Created by Elia Baitel on 7/26/16.
//  Copyright © 2016 infinernet. All rights reserved.
//

import UIKit
import CoreMotion
import CoreData

class ViewController: UIViewController {

    @IBOutlet weak var imgView: UIImageView!


    let manager = CMMotionManager()


    override func viewDidLoad() {
        super.viewDidLoad()


        let manager = CMMotionManager()
        if manager.gyroAvailable {
            // ...
        }
        manager.gyroUpdateInterval = 0.1
        manager.startGyroUpdates()
        let queue = NSOperationQueue.mainQueue()
        manager.startGyroUpdatesToQueue(queue) {
            (data, error) in
            // ...
        }

        // get magnitude of vector via Pythagorean theorem
        func magnitudeFromAttitude(attitude: CMAttitude) -> Double {
            return sqrt(pow(attitude.roll, 2) + pow(attitude.yaw, 2) + pow(attitude.pitch, 2))
        }

        // initial configuration
        var initialAttitude = manager.deviceMotion!.attitude
        var showingPrompt = false

        // trigger values - a gap so there isn't a flicker zone
        let showPromptTrigger = 1.0
        let showAnswerTrigger = 0.8

        if manager.deviceMotionAvailable {
            manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
                [weak self] (data: CMDeviceMotion?, error: NSError?) in

                guard let data = data else { return }

                // translate the attitude
                data.attitude.multiplyByInverseOfAttitude(initialAttitude)

                // calculate magnitude of the change from our initial attitude
                let magnitude = magnitudeFromAttitude(data.attitude) ?? 0

                // show the prompt
                if !showingPrompt && magnitude > showPromptTrigger {
                    if let promptViewController = self?.storyboard?.instantiateViewControllerWithIdentifier("PromptViewController") as? PromptViewController {
                        showingPrompt = true

                        promptViewController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
                        self?.presentViewController(promptViewController, animated: true, completion: nil)
                    }
                }

                // hide the prompt
                if showingPrompt && magnitude < showAnswerTrigger {
                    showingPrompt = false
                    self?.dismissViewControllerAnimated(true, completion: nil)
                }
            }
        }






        // get magnitude of vector via Pythagorean theorem
           }}

但我收到一条错误消息,指出使用未声明类型&#34; PromptViewController&#34;

以下是http://i.stack.imgur.com/FpVuh.jpg

的图片

0 个答案:

没有答案