2010-06-06 15 views
0

我試圖從Apple實現ViewTransitions代碼示例,但將所有的邏輯放在我的viewController而不是我的applicationDelegate類中。在viewController中使用CATransition

我在嘗試編譯時遇到了一個奇怪的錯誤。

_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 
+0

這將有助於您發佈您的代碼,特別是您設置轉換的區域。 – 2010-06-06 22:59:02

回答

10

您需要將QuartzCore.framework添加到您的目標。

1)展開「目標」 2)選擇應用程序的配置 3)Cmd的+ I /獲取信息 4)在「鏈接庫」部分按「+」按鈕,並從選擇QuartzCore.framework名單。

你現在應該可以編譯了。

+0

偉大的幫助。 – 2010-07-23 03:45:15