2017-11-04 15 views
7

मैं एक ऐप बना रहा हूं जो परिदृश्य में पैनोरामा वीडियो बनाने में सक्षम है। परिदृश्य में, यह दो दिशाओं का समर्थन करता है: बाएं से दाएं और नीचे से ऊपर।कोरमोशन - परिदृश्य में आईफोन पर बाएं-दाएं, नीचे-ऊपर आंदोलन प्राप्त करें

तो मैं बाएं से दाएं स्थानांतरित करने के लिए बाएं से दाएं स्थानांतरित करना चाहता हूं जब उपयोगकर्ता फ़ोन को बाएं से दाएं या दाईं ओर घुमाता है। डिवाइस को ऊर्ध्वाधर ऊपर ऊपर ले जाने पर भी तीर नीचे शीर्ष पर जाना चाहते हैं। पैनोरामा विकल्प के साथ देशी आईफोन कैमरा ऐप में, हम सही सिमुलेशन देख सकते हैं,

मेरे प्रश्न हैं 1) मुझे कैसे पता चलेगा कि उपयोगकर्ता फोन को बाएं से दाएं या दाएं से बाएं स्थानांतरित कर रहा है। चूंकि आईफोन पैनोरमा की तरह, मैं रिकॉर्डिंग को रोकना चाहता हूं जब उपयोगकर्ता वापस चलेगा।

इसके अलावा 2) कैसे मैं जानता हूँ कि उपयोगकर्ता खड़ी ऊपर की तरफ


फोन बढ़ रहा है कर जोड़ा गया: नवम्बर 10, 2017: मैं एक ऐप्स AppStore में Spincle नामित देखा था। 360 छवि लेने के लिए डिवाइस को बाएं से दाएं घुमाने पर तीर को स्थानांतरित कर रहा है। मैं सिर्फ पिच और रोल का उपयोग करके इसे प्राप्त करने में कामयाब रहा (नीचे कोड देखें)। लेकिन अगर हम उपकरण को फर्श या छत पर खड़े करते हैं तो यह काम नहीं करेगा।

import UIKit 
import CoreMotion 
class ViewController: UIViewController { 
    private let motionManager = CMMotionManager() 
    let arrowView = UIView() 
    func startMotion() { 
     var initialAttitude: CMAttitude? 
     motionManager.deviceMotionUpdateInterval = 1 
     let queue = OperationQueue.current! 
     let statusBarOrientation = UIApplication.shared.statusBarOrientation 
     motionManager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrame.xArbitraryZVertical, to: queue) { (motiondata, err) in 
      guard let data = motiondata else { return } 
      if initialAttitude == nil { 
       initialAttitude = data.attitude 
      } else { 
       let attitude = data.attitude 
       // translate the attitude 
       attitude.multiply(byInverseOf: initialAttitude!) 
       // calculate pitch and roll of the change from our initial attitude 
       let pitch = self.radiansToDegrees(attitude.pitch) 
       let roll = self.radiansToDegrees(attitude.roll) 
       print("\nroll = \(roll), pitch = \(pitch), yaw = \(self.radiansToDegrees(attitude.yaw))") 
       print("x = \(data.userAcceleration.x), y = \(data.userAcceleration.y), z = \(data.userAcceleration.z)") 
       DispatchQueue.main.async { 
        var rect = self.arrowView.frame 
        var addXPixel = self.view.frame.size.width/45 
        var addYPixel = self.view.frame.size.height/45 
        if statusBarOrientation == .landscapeRight { 
         addXPixel *= -1 
        } else { 
         addYPixel *= -1 
        } 
        rect.origin.x = (CGFloat(pitch) * addXPixel) 
        rect.origin.y = (self.view.frame.size.height/2 - 20) + (CGFloat(roll) * addYPixel) 
        self.arrowView.frame = rect 
       } 
      } 
     } 
    } 
    func stopMotion() { 
     motionManager.stopDeviceMotionUpdates() 
    } 
    func radiansToDegrees(_ radian: Double) -> Float { 
     return Float(radian * 180.0/Double.pi) 
    } 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     view.addSubview(arrowView) 
     arrowView.backgroundColor = UIColor.red 
    } 
    @IBAction func tappedButton() { 
     arrowView.frame = CGRect(x: 0, y: self.view.frame.size.height/2 - 20, width: 40, height: 40) 
     startMotion() 
    } 
} 

मुद्दा यह थोड़ा और तीर ऊपर की तरफ या नीचे की ओर

चलती बाएं से दाएं जाएंगे

उत्तर

1

आप अपने फोन के शीर्षक की जाँच करें, और लिखना अपने एल्गोरिथ्म बाईं निर्धारित करने के लिए करने के लिए उपयोग कर सकते हैं CLLocationManagerCLHeading की डिग्री की गणना करके दाएं/नीचे-शीर्ष आंदोलन।

- (void)locationManager:(CLLocationManager*)manager 
     didUpdateHeading:(CLHeading*)newHeading 

https://developer.apple.com/documentation/corelocation/clheading

+0

मुझे जाँच करें। लेकिन स्पिनकल ऐप भी काम करता है भले ही स्थान डेटा बंद हो। – jpulikkottil

संबंधित मुद्दे