问题描述
这堂课将使视角直立起来.
This class will put perspective on an upright image.
它完美运行,但不能在带有IBDesignable的情节提要中实时运行.真伤心.
It works perfectly BUT does not work live in Storyboard with IBDesignable. Which is very sad.
是否可以使用IBDesignable在演示板上实时显示CATransform3D之类的内容?
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);
}
}
推荐答案
实时预览转换已经存在问题.看来这似乎行不通,也许还没有实施.
I already had an issue with live preview transformations. It seems it just doesn't work, maybe not implemented yet.
有一件事,只有UIView
可以是@IBDesignable.在这里,您可以看到不能同时渲染两个@UIDesignable类.我为该示例创建了TwistableView类.
There's a thing, only UIView
s can be @IBDesignable. Here you can see that both of @UIDesignable classes can't be rendered. I created a Class TwistableView for the example.
这篇关于层转换矩阵(CATransform3D等)但具有IBDesignable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!