我想在UIView上执行透视变换(例如在coverflow中看到)
有谁知道这是否可能?
我已经调查过使用CALayer并且已经完成了所有实用的程序员Core Animation播客,但我仍然不清楚如何在iPhone上创建这种转换.
任何帮助,指针或示例代码片段将非常感谢!
我想从当前的图形上下文创建一个UIImage对象.更具体地说,我的用例是用户可以绘制线条的视图.他们可以逐步绘制.完成后,我想创建一个UIImage来代表他们的绘图.
这是drawRect:现在对我来说是这样的:
- (void)drawRect:(CGRect)rect
{
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSaveGState(c);
CGContextSetStrokeColorWithColor(c, [UIColor blackColor].CGColor);
CGContextSetLineWidth(c,1.5f);
for(CFIndex i = 0; i < CFArrayGetCount(_pathArray); i++)
{
CGPathRef path = CFArrayGetValueAtIndex(_pathArray, i);
CGContextAddPath(c, path);
}
CGContextStrokePath(c);
CGContextRestoreGState(c);
}
Run Code Online (Sandbox Code Playgroud)
...其中_pathArray的类型为CFArrayRef,并且每次调用touchesEnded:时都会填充.另请注意,drawRect:可以在用户绘制时多次调用.
用户完成后,我想创建一个表示图形上下文的UIImage对象.有关如何做到这一点的任何建议?
我已阅读并试用这篇文章(使用Core Animation打开门效果)
我在我的应用程序中实现以下代码:
CALayer *layer = threeHomeView.layer;
CATransform3D initialTransform = threeHomeView.layer.transform;
initialTransform.m34 = 1.0 / -900;
[UIView beginAnimations:@"Scale" context:nil];
[UIView setAnimationDuration:3];
layer.transform = initialTransform;
CATransform3D rotationAndPerspectiveTransform = threeHomeView.layer.transform;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform
, 40.0f * M_PI / 180.0f
, 0.0f
, 1.0f
, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(threeHomeFlyOut)];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
threeHomeView是一个UIImageView.
我的问题是:图像只能通过图像的中间垂直线旋转,但我想让它按图像的左垂直线旋转.
我正在寻找有关如何在我的iOS项目中实现流行的"纸张折叠/折纸"效果的提示.
我知道的项目如:https: //github.com/xyfeng/XYOrigami 但他们只提供'动画'效果,没有手动控制开场动画.
我一直在努力剖析那个项目并想出我所追求的目标.
更确切地说,我正在研究如何实现此处显示的效果:http://vimeo.com/41495357其中折叠动画不仅仅是动画打开,而是用户控制开始折叠.
任何帮助将非常感谢,提前感谢!
编辑:
好的,这里有一些示例代码可以更好地说明我正在努力解决的问题:
此方法触发折纸效果动画:
- (void)showOrigamiTransitionWith:(UIView *)view
NumberOfFolds:(NSInteger)folds
Duration:(CGFloat)duration
Direction:(XYOrigamiDirection)direction
completion:(void (^)(BOOL finished))completion
{
if (XY_Origami_Current_State != XYOrigamiTransitionStateIdle) {
return;
}
XY_Origami_Current_State = XYOrigamiTransitionStateUpdate;
//add view as parent subview
if (![view superview]) {
[[self superview] insertSubview:view belowSubview:self];
}
//set frame
CGRect selfFrame = self.frame;
CGPoint anchorPoint;
if (direction == XYOrigamiDirectionFromRight) {
selfFrame.origin.x = self.frame.origin.x - view.bounds.size.width;
view.frame = CGRectMake(self.frame.origin.x+self.frame.size.width-view.frame.size.width, self.frame.origin.y, view.frame.size.width, view.frame.size.height);
anchorPoint = CGPointMake(1, 0.5);
}
else …Run Code Online (Sandbox Code Playgroud) 之前已经问过这个问题,但是就我所知,在stackoverflow上找不到示例代码,也没有适当的解决方案.我有一个解决方案,但它看起来很糟糕.我很感激任何输入和修改,以获得更逼真的3D门打开/书籍封面动画.
目标是在UIViewControllers之间创建一个动画,以便您获得效果,就像打开一扇门或书籍封面一样.ViewController 2是静态的并且在后台.在它上面你放置了ViewController 1,它覆盖了ViewController 2.动画将打开ViewController 1(就像一本精装书),并显示ViewController 2(你的第一页可以说,或门后面的任何东西).
首先要注意的是,您无法使用UINavigationController执行此操作,因为很难覆盖自定义动画.可以在此处找到有关如何设置两个ViewControllers的正确教程:ViewController动画
所以一旦设置完毕,这是我的自定义动画,看起来很糟糕.它看起来好像是在向左挤压书的门/盖.我担心没有3D感觉.任何有关如何做到这一点的建议都会受到欢迎:
-(void)openDoorTo:(UIViewController *)aController duration:(float)aDuration {
[aController viewWillAppear:YES];
[activeController viewWillDisappear:YES];
[self.view insertSubview:aController.view belowSubview:activeController.view]; // so that it is below activeController
[aController viewDidAppear:YES];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:aDuration];
aController.view.transform = CGAffineTransformMakeTranslation(0,0);
CATransform3D _3Dt = CATransform3DIdentity;
_3Dt = CATransform3DTranslate(_3Dt, -320, 0, 0);
_3Dt = CATransform3DRotate(_3Dt, M_PI * 1.5, 0.0, 1, 0.0);
_3Dt = CATransform3DTranslate(_3Dt, 320, 0, 0);
activeController.view.layer.transform = _3Dt;
[UIView commitAnimations];
[self performSelector:@selector(animationDone:) withObject:aController afterDelay:aDuration];
}
Run Code Online (Sandbox Code Playgroud)
我认为主要的问题是我真的不知道如何处理CATransform3DTranslate和CATransform3DRotate.
这里有一些帖子,但我真的不知道如何将它们应用到3D开门器: