本课程将透视直立图像.
它完美地工作但是在IBDesignable的Storyboard中不能正常工作.哪个很难过.
是否可以使用CATransform3D等在带有IBDesignable的Storyboard上进行实时显示?
// 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);
}
}
最佳答案 我已经遇到了实时预览转换的问题.它似乎不起作用,也许还没有实现.
有一件事,只有UIViews可以是@IBDesignable.在这里,您可以看到无法呈现两个@UIDesignable类.我为这个例子创建了一个Class TwistableView.