在倾斜手机上变换3d视图

时间:2019-03-05 16:38:30

标签: ios swift

我想改变我对手机倾斜的看法。目标是用2d视图制作3d效果。

我使用CoreMotion的Sub ListVideosOnPage(VidCatName As String, VidCatURL As String) Dim XMLReq As New MSXML2.XMLHTTP60 Dim HTMLDoc As New MSHTML.HTMLDocument Dim VidRow As MSHTML.IHTMLElement Dim VidInnerRow As MSHTML.IHTMLElement Dim VidRows As MSHTML.IHTMLElementCollection Dim VidInnerRows As MSHTML.IHTMLElementCollection Dim VidInnerCatID As Integer XMLReq.Open "GET", VidCatURL, False XMLReq.send If XMLReq.Status <> 200 Then MsgBox "Problem" & vbNewLine & XMLReq.Status & " - " & XMLReq.statusText Exit Sub End If HTMLDoc.body.innerHTML = XMLReq.responseText Set XMLReq = Nothing Set VidRows = HTMLDoc.getElementsByClassName("bptable") Set VidInnerRows = ***VidRows***.getElementsByTagName("a") With VidRows For VidInnerCatID = 2 To VidInnerRows.Length Set VidInnerRow = VidInnerRows(VidInnerCatID) 'Debug.Print Next VidInnerCatID End With End Sub 获取数据以转换视图:

device motion

然后我用fileprivate func startDeviceMotionNotifications() { guard self.motionManager.isDeviceMotionAvailable else { return } self.motionManager.startDeviceMotionUpdates(to: OperationQueue.main, withHandler: { (data, error) in if let attitude = data?.attitude, error == nil { let radians = atan2(attitude.roll, attitude.pitch) - .pi // Convert pitch and roll to [-1, 1] range let pitch = CGFloat(-attitude.pitch * 2 / .pi) let roll = CGFloat(abs(attitude.roll) > .pi / 2 ? (2 - abs(attitude.roll) * 2 / .pi) * (attitude.roll > 0 ? 1 : -1) : attitude.roll * 2 / .pi) // Calculate x and y let y = pitch let x = roll*(1.0-abs(pitch)) NotificationCenter.default.post(name: Notification.Name(rawValue: MotionManager.notificationName), object: nil, userInfo: ["x": x, "y": y, "radian": radians]) } }) } 转换了视图:

CATransform3DRotate

使用此代码,视图正在移动但不平滑,并且当手机处于垂直状态时,它将停止移动。

完美的例子是在应用func skew(rotation:CGFloat, x:CGFloat, y:CGFloat) { var transform = CATransform3DIdentity transform.m34 = -1.0/500.0 transform = CATransform3DRotate(transform, rotation * (.pi / 180), y, x, 0) transform = CATransform3DScale(transform, 0.99, 0.99, 1) self.layer.transform = transform } 中。配置文件中的所有卡(如果点击用户名卡,您都可以看到它)正在与陀螺仪完美移动。任何想法要得到这个结果?

0 个答案:

没有答案