我试图弄清楚如何使用核心动画在我的iPad应用程序中创建a curl or peel effect on an image,但当我学习应用程序接口时,我只了解移动、缩放和旋转2D图像(包括3D转换)的不同方式。我想在两面都有图像的小的,单独的层(即精灵)上实现这个效果,所以当你剥离这一层时,你在背面暴露了图像。我还需要控制图层剥离的位置和角度。我的数学很糟糕,我希望有比我更聪明的人能帮助我,只要我至少理解了我提到的那些基本的转换。
非常感谢您的智慧!
发布于 2010-07-08 00:29:31
轻松创建它的唯一方法是使用UIView的类方法,如下所示:
此代码位于MyViewController.h文件中:
@interface MyViewController : UIViewController
{
UIImageView* imageView1;
UIImageView* imageView2;
}
@end下面的代码放在MyViewController.m文件中:
@implementation MyViewController
- (void) dealloc
{
[imageView2 release];
[imageView1 release];
[super dealloc];
}
- (void) loadView
{
self.view = [[UIView alloc] initWithFrame : CGRectMake (0, 0, 768, 1004)];
UIImage* image1 = [[UIImage alloc] initWithContentsOfFile : @"image1.png"];
UIImage* image2 = [[UIImage alloc] initWithContentsOfFile : @"image2.png"];
imageView1 = [[UIImageView alloc] initWithImage : image1];
imageView2 = [[UIImageView alloc] initWithImage : image2];
[imageView1 setFrame : CGRectMake (0, 0, 768, 1004)];
[imageView1 setFrame : CGRectMake (0, 0, 768, 1004)];
[self.view addSubview : imageView1];
[image2 release];
[image1 release];
}
- (void) viewDidUnload
{
imageView2 = nil;
imageView1 = nil;
[super viewDidUnload];
}
- (void) touchesBegan : (NSSet*) touches withEvent : (UIEvent*) event
{
[UIView beginAnimations : nil context : nil];
[UIView setAnimationCurve : UIViewAnimationCurveLinear];
[UIView setAnimationDuration : 0.25];
if (imageView1.superview != nil)
{
[UIView setAnimationTransition : UIViewAnimationTransitionCurlUp forView : self.view cache : YES];
[imageView1 removeFromSuperview];
[self.view addSubview : imageView2];
}
else
{
[UIView setAnimationTransition : UIViewAnimationTransitionCurlDown forView : self.view cache : YES];
[imageView2 removeFromSuperview];
[self.view addSubview : imageView1];
}
[UIView commitAnimations];
}
@end在本例中,由于UIViewController是以编程方式创建的,因此使用方法"loadView“来创建由视图控制器管理的视图和该视图将管理的子视图。我希望这能帮到你。干杯。
发布于 2010-07-07 22:46:13
在大多数情况下,您可以跳过数学运算,让api处理所有事情。尝试以下代码:
- (IBAction)showPeelBack:(id)sender{
FooController *controller = [[CreditsController alloc] initWithNibName:@"Foo" bundle:nil];
// setup the stuff you want to display
[controller setViewController: self];
controller.modalPresentationStyle = UIModalPresentationFullScreen;
controller.modalTransitionStyle = UIModalTransitionStylePartialCurl;
// note: I'm using a nav controller here
[[self navigationController] presentModalViewController:controller animated:YES];
[controller release];
}https://stackoverflow.com/questions/3194777
复制相似问题