2012-01-24 40 views
0

今天我遇到了一個奇怪的問題。我有一個iPhone和iPad的應用程序,它是一個通用的應用程序,但我做了兩個主視圖控制器,一個用於iPhone和一個用於iPad。我首先製作了iPhone版...然後我將一些代碼複製到iPad版本。除了我的標誌UIImageView,一切似乎都很好。我有一個從屏幕下滑到導航欄中心的標誌。在動畫之前,我將UIImageView設置爲脫屏,然後可以滑下。但是,即使我在uiimageview框架的x和y中放置了任意的隨機值,它仍然是0,0。這與我在iPhone上的代碼相同,並且工作正常。UIImageView無法在iPad上正確定位(始終位於0,0)

這是我的初始化。

UIImage *logoText = [UIImage imageNamed:@"logotext.png"]; 
    [logoTextView setUserInteractionEnabled:YES]; 
    logoTextView = [[UIImageView alloc] init]; 
    // I already tried [[UIImageView alloc] initWithFrame:CGRectMake......]; 
    logoTextView.frame = CGRectMake(389, -100, logoText.size.width, logoText.size.height); 
    logoTextView.image = logoText; 
    logoTextView.center = CGPointMake(389, -100); 
    logoTextView.alpha = 1; 
    [logoTextView addGestureRecognizer:resetGesture]; 
    // [logoTextView setBackgroundColor:[UIColor whiteColor]]; 
    [self.view insertSubview:logoTextView atIndex:10]; 

這實際上應該將UIImageView放置在屏幕的中心和100px之外。但沒有任何反應。它仍然是0,0。我嘗試了所有我知道的方式,沒有什麼效果......

有人知道,該怎麼辦?這真的會幫助我。 :)

編輯

我剛纔已經找到了解決辦法...我不知道爲什麼,但如果在一個新的方法...奇怪這僅適用。

- (void)logoShow { 

    UITapGestureRecognizer *resetGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetValues)]; 

    UIImage *logoText = [UIImage imageNamed:@"[email protected]x.png"]; 
    logoTextView = [[UIImageView alloc] initWithFrame:CGRectMake(389, -50, logoText.size.width/1.35, logoText.size.height/1.35)]; 
    logoTextView.center = CGPointMake(389, -50); 
    logoTextView.image = logoText; 
    logoTextView.alpha = 1; 
    [logoTextView addGestureRecognizer:resetGesture]; 
    [self.view insertSubview:logoTextView atIndex:15]; 


    // LOGO TEXT ANIMATION 
    [UIView beginAnimations:@"Logo Text Animation" context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDelay:4.5]; 
    [UIView setAnimationDuration:0.5]; 
    logoTextView.alpha = 1; 
    logoTextView.center = CGPointMake(389, 22); 
    [UIView commitAnimations]; 
    [logoTextView setUserInteractionEnabled:YES]; 
} 
+0

這不是一個解決方案,但'-initWithFrame:'是「UIView」和子類的指定初始值設定項,而不是「init」。 – nielsbot

+0

謝謝,我已經試過了。也不行:/ –

+0

好吧,我說這不是一個解決方案,但我相信這是一個很好的做法。 – nielsbot

回答

0

我會設置標識視圖作爲我的視圖控制器的標題視圖。在您的-initWithNib(或類似)這樣做:

logoTextView.alpha = 0.0f ; 
self.navigationItem.titleView = logoTextView ; 

然後在你的-viewDidAppear:方法做到這一點:

CALayer * layer = logoTextView.layer ; 
{ 
    CABasicAnimation * anim = [ CABasicAnimation animationWithKeyPath:@"transform" ] ; 
    anim.fromValue = [ NSValue valueWithCATransfom3D: 
         CATransform3DMakeTranslate(0, -100.0f, 0) ] ; 
    [ layer addAnimation:anim forKey:nil ] ; 
} 
logoTextView.alpha = 1.0f ; 

好運

+0

嘿,謝謝你,但它給了我一個錯誤,說沒有「valueWithCATransform3D」的已知類方法...:/ 實際上,我想開始標誌離屏幕,然後將其滑動到導航吧:) –

+0

你鏈接了QuartzCore框架的工作嗎? – nielsbot

+0

我認爲我給你的代碼將從屏幕外動畫......嘗試一下,看看它是否工作 – nielsbot