简体   繁体   English

iOS UIView 3D边框

[英]iOS UIView 3D border

I have been working on coin like UIView, which has 3d rotation. 我一直在研究UIView等具有3D旋转的硬币。

I was able to implement rotate effect with CATransform3dRotate, based on the gesture. 我能够基于手势使用CATransform3dRotate实现旋转效果。 Now I need to implement shadow like effect, when image rotates. 现在,当图像旋转时,我需要实现类似阴影的效果。

Please refer to the image attached herewith. 请参考随附的图像。

Any suggestions? 有什么建议么? recommendations? 建议? or sample code would be great 否则示例代码会很棒

Sample Requirement 样品要求

You might want to look at SceneKit . 您可能想看看SceneKit I've put together a quick demo, which you can download here , of a 3D coin object which rotates horizontally left or right by a swipe gesture, with a realistic light source and shadowing. 我整理了一个3D硬币对象的快速演示,可以在此处下载,该3D硬币对象通过滑动手势向左或向右旋转,并带有真实的光源和阴影。 The relevant code follows: 相关代码如下:

import UIKit
import SceneKit

class ViewController: UIViewController {

    @IBOutlet weak var sceneView: SCNView!

    let rotate90AboutZ = SCNAction.rotateByX(0.0, y: 0.0, z: CGFloat(M_PI_2), duration: 0.0)

    var currentAngle: Float = 0.0
    var coinNode = SCNNode()

    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView.userInteractionEnabled = true
        sceneView.backgroundColor = UIColor.blackColor()
        sceneView.autoenablesDefaultLighting = true
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)
        coinSceneSetup()
    }

    func coinSceneSetup() {

        let coinScene = SCNScene()
        //coin is rendered as a cylinder with a very small height
        let coinGeometry = SCNCylinder(radius: 50, height: 2)
        coinNode = SCNNode(geometry: coinGeometry)
        coinNode.position = SCNVector3Make(0.0, 25.0, 25.0)
        coinScene.rootNode.addChildNode(coinNode)
        //rotate coin 90 degrees about the z axis so that it stands upright
        coinNode.runAction(rotate90AboutZ)

        let shinyCoinMaterial = SCNMaterial()
        shinyCoinMaterial.diffuse.contents = UIColor.lightGrayColor()
        shinyCoinMaterial.specular.contents = UIColor.whiteColor()
        shinyCoinMaterial.shininess = 1.0
        coinGeometry.firstMaterial = shinyCoinMaterial
        sceneView.scene = coinScene
        let panRecognizer = UIPanGestureRecognizer(target: self, action: "panGesture:")
        sceneView.addGestureRecognizer(panRecognizer)
    }

    //allows for coin to spin with a right or left finger swipe, while still keeping it rotated 90 degrees about z axis
    func panGesture(sender: UIPanGestureRecognizer) {
        let translation = sender.translationInView(sender.view!)
        var newAngle = (Float)(translation.x)*(Float)(M_PI)/180.0
        newAngle += currentAngle
        coinNode.runAction(SCNAction.rotateToX(CGFloat(newAngle), y: 0.0, z: CGFloat(M_PI_2), duration: 0.0))
        if(sender.state == UIGestureRecognizerState.Ended) {
            currentAngle = newAngle
        }
    }      
}

Several excellent introductory tutorials are available, for example here , here , and here . 提供了一些出色的入门教程,例如, 此处此处此处 weheartswift.com put out a three part tutorial in Swift that I personally find especially useful. weheartswift.com在Swift中发布了一个三部分的教程,我个人觉得特别有用。 Here are parts 1 , 2 and 3 . 这是 1、23部分

Jeff Lamarche's introduction to SceneKit on OS X, along with his accompanying source code is a valuable resource as well. Jeff Lamarche对OS X上的SceneKit的介绍 ,以及他附带的源代码也是宝贵的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM