Layer transform matrix (CATransform3D, etc.) but with IBDesignable?

雨燕双飞 提交于 2020-01-02 06:31:30

问题


This class will put perspective on an upright image.

It works perfectly BUT does not work live in Storyboard with IBDesignable. Which is very sad.

Is it possible to use CATransform3D and the like for live display on Storyboard with IBDesignable??

// Twist.swift .. twist on Y, perspective from the left
import UIKit
@IBDesignable
class Twist:UIViewController
    {
    @IBInspectable var perspective:CGFloat = 0.5        // -1 to 1

    @IBOutlet var im:UIView!    // the image you want to twist on y

    override func prepareForInterfaceBuilder()
        { twist(perspective) }

    override func viewDidAppear(animated: Bool)
        {
        twist(perspective)
        super.viewWillAppear(animated)
        }

    func twist(f:CGFloat)           // -1 to 1
        {
        // hinge around left edge
        im.layer.anchorPoint = CGPointMake(0, 0.5)
        im.center = CGPointMake(0.0, self.view.bounds.size.height/2.0)

        // base transform, twist on y
        var t:CATransform3D = CATransform3DIdentity
        t.m34 = -1/500
        im.layer.transform = t
        im.layer.transform = CATransform3DRotate(t, f*CGFloat(M_PI_2), 0, 1, 0);
        }
    }

回答1:


I already had an issue with live preview transformations. It seems it just doesn't work, maybe not implemented yet.

There's a thing, only UIViews can be @IBDesignable. Here you can see that both of @UIDesignable classes can't be rendered. I created a Class TwistableView for the example.



来源:https://stackoverflow.com/questions/37311649/layer-transform-matrix-catransform3d-etc-but-with-ibdesignable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!