我怎样写等效于CATransform3D的
CGPoint CGPointApplyAffineTransform(CGPoint point, CGAffineTransform t)
CGSize CGSizeApplyAffineTransform(CGSize size, CGAffineTransform t);
CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t);
?
最佳答案
这可以工作,但是知道-[CALayer convertPoint:toLayer:]
里面发生了什么,当然更好了!CGPoint CGPointApplyCATransform3D(CGPoint point, CATransform3D transform, CGPoint anchorPoint, CATransform3D parentSublayerTransform)
{
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static CALayer *sublayer, *layer;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sublayer = [CALayer layer];
layer = [CALayer layer];
[layer addSublayer:sublayer];
});
if(pthread_mutex_lock(&mtx))
{
[NSException raise:NSInternalInconsistencyException format:@"pthread_mutex_lock failed"];
}
layer.sublayerTransform = parentSublayerTransform;
sublayer.transform = transform;
sublayer.anchorPoint = anchorPoint;
CGPoint retval = [sublayer convertPoint:point toLayer:layer];
if(pthread_mutex_unlock(&mtx) != 0)
{
[NSException raise:NSInternalInconsistencyException format:@"pthread_mutex_unlock failed"];
}
return retval;
}
简单单元测试https://gist.github.com/hfossli/5130975