小编jpu*_*til的帖子

CoreMotion - 在iPhone上横向移动,自下而上

我正在制作一个能够在风景中制作全景视频的应用程序.在横向上,它支持两个方向:从左到右,从下到上.

因此,当用户从左向右移动手机或向右旋转时,我想从左向右移动箭头.当垂直向上移动设备时,也希望将箭头从底部移到顶部.在具有全景选项的原生iPhone相机应用程序中,我们可以看到正确的模拟,

我的问题是1)我怎么知道用户正在从左到右或从右到左移动手机.因为像iPhone全景,我想在用户搬回时停止录制.

另外2)我怎么知道用户正在垂直向上移动手机


补充:2017年11月10日:我确实在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 …
Run Code Online (Sandbox Code Playgroud)

accelerometer ios core-motion swift

7
推荐指数
1
解决办法
509
查看次数

为数组中所有对象的属性设置相同值的最佳方法

class Cell {
    var isSelected = true
}
var array: [Cell] = [Cell(), Cell(), Cell()]
Run Code Online (Sandbox Code Playgroud)

现在我想将数组中的所有对象的 isSelected 属性设置为“false”。

我们可以通过 for 循环来实现,也可以使用 map

_ = array.map {$0.isSelected.true}

但我认为会有更好的解决方案。

arrays sequence swift

1
推荐指数
1
解决办法
2038
查看次数

标签 统计

swift ×2

accelerometer ×1

arrays ×1

core-motion ×1

ios ×1

sequence ×1