在 viewController 中使用 CATransition

发布于 2024-09-04 06:39:54 字数 2742 浏览 4 评论 0原文

我正在尝试实现 Apple 的 ViewTransitions 代码示例,但将所有逻辑放在我的 viewController 而不是 applicationDelegate 类中。

当我尝试编译时出现奇怪的错误。

_kCATransitionFade", referenced from:
  _kCATransitionFade$non_lazy_ptr in ViewTransitionsAsViewControllerViewController.o
 (maybe you meant: _kCATransitionFade$non_lazy_ptr)

有人有什么想法吗?

回答第一条评论,这是我的整个 viewController 实现。与 Apple ViewTranstions 代码的唯一真正区别是,我将逻辑从“applicationDidFinishLaunching”方法移动到“viewDidLoad”方法。

#import "ViewTransitionsAsViewControllerViewController.h"
#import <QuartzCore/QuartzCore.h>


@implementation ViewTransitionsAsViewControllerViewController
@synthesize containerView, doTransitionButton;
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {  
UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil]];
view1 = [[UIImageView alloc] initWithImage:image1];
UIImage *image2 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image2.jpg" ofType:nil]];
view2 = [[UIImageView alloc] initWithImage:image2];
view2.hidden = YES;
[containerView addSubview:view1];
[containerView addSubview:view2];
transitioning = NO;

[super viewDidLoad];
}

 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }

-(void)dealloc
{
[containerView release];
[view1 release];
[view2 release];
[super dealloc];
}

-(void)performTransition
{ 
// First create a CATransition object to describe the transition
CATransition *transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction      
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionFade;
transitioning = YES;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[containerView.layer addAnimation:transition forKey:nil];
// Here we hide view1, and show view2, which will cause Core Animation to animate view1 away and view2 in.
view1.hidden = YES;
view2.hidden = NO;
 // And so that we will continue to swap between our two images, we swap the instance variables     referencing them.
UIImageView *tmp = view2;
view2 = view1;
view1 = tmp;
}

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
 transitioning = NO;
}

-(IBAction) doTransition:(id)sender
{
 if(!transitioning)
{
[self performTransition];
}
}
@end

I'm trying to implement the ViewTransitions code sample from Apple, but putting all the logic in my viewController instead of my applicationDelegate class.

I'm getting a bizarre error when I try to compile.

_kCATransitionFade", referenced from:
  _kCATransitionFade$non_lazy_ptr in ViewTransitionsAsViewControllerViewController.o
 (maybe you meant: _kCATransitionFade$non_lazy_ptr)

Anyone have any ideas?

Answering the 1st comment, this is my entire viewController implementation. The only real difference from the Apple ViewTranstions code is that I am moving the logic from the 'applicationDidFinishLaunching' method to my 'viewDidLoad' method.

#import "ViewTransitionsAsViewControllerViewController.h"
#import <QuartzCore/QuartzCore.h>


@implementation ViewTransitionsAsViewControllerViewController
@synthesize containerView, doTransitionButton;
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {  
UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil]];
view1 = [[UIImageView alloc] initWithImage:image1];
UIImage *image2 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image2.jpg" ofType:nil]];
view2 = [[UIImageView alloc] initWithImage:image2];
view2.hidden = YES;
[containerView addSubview:view1];
[containerView addSubview:view2];
transitioning = NO;

[super viewDidLoad];
}

 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }

-(void)dealloc
{
[containerView release];
[view1 release];
[view2 release];
[super dealloc];
}

-(void)performTransition
{ 
// First create a CATransition object to describe the transition
CATransition *transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction      
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionFade;
transitioning = YES;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[containerView.layer addAnimation:transition forKey:nil];
// Here we hide view1, and show view2, which will cause Core Animation to animate view1 away and view2 in.
view1.hidden = YES;
view2.hidden = NO;
 // And so that we will continue to swap between our two images, we swap the instance variables     referencing them.
UIImageView *tmp = view2;
view2 = view1;
view1 = tmp;
}

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
 transitioning = NO;
}

-(IBAction) doTransition:(id)sender
{
 if(!transitioning)
{
[self performTransition];
}
}
@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2024-09-11 06:39:54

您需要将 QuartzCore.framework 添加到您的 Target 中。

1) 展开“目标”
2) 选择您配置的应用程序
3) Cmd + I / 获取信息
4) 在“Linked Libraries”部分下按“+”按钮并从列表中选择 QuartzCore.framework。

您现在应该可以编译了。

You need to add the QuartzCore.framework to your Target.

1) Expand "Targets"
2) Select the App your configuring
3) Cmd + I / Get Info
4) Under the "Linked Libraries" section press the "+" button and select QuartzCore.framework from the list.

You should be able to compile now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文