2014-03-24 84 views
0

這裏查看過渡口吃是一種過渡的代碼我有顯示ViewB從ViewA當鍵盤出現的iOS

CGPoint c = thepoint; 
CGFloat tx = c.x - floorf(theview.center.x) + 10; 
CGFloat ty = c.y - floorf(theview.center.y) + 100; 

[UIView animateWithDuration:0.5 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        // Transforms 
        CGAffineTransform t = CGAffineTransformMakeTranslation(tx, ty); 
        t = CGAffineTransformScale(t, 0.1, 0.1); 
        theview.transform = t; 
        theview.layer.masksToBounds = YES; 
        [theview setTransform:CGAffineTransformIdentity]; 

       } 
       completion:^(BOOL finished) { 

       }]; 

現在過渡去沒有問題,很順利。

當我在我的ViewB中,我有一個默認焦點的文本框。 (在viewDidAppear

-(void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:NO]; 
    [self performSelector:@selector(focusCommentText) withObject:nil afterDelay:0.5]; 
} 

- (void) focusCommentText { 
[self focusTextbox:commentText]; 
} 

- (void) focusTextbox : (UITextView *) textView{ 
    @try { 
     [ textView becomeFirstResponder]; 
    } 
    @catch (NSException *exception) { 

    } 
} 

轉型與鍵盤來了..發生在同一時間。而現在略顯尷尬。有人能幫我一下嗎?

+1

這只是意味着這兩個動畫不能與當前一代的硬件性能良好同時運行。你需要找到一種方法,不要同時做這兩個動畫。 –

+0

@AbhiBeckert你是對的!我按照你的說法修復了我的代碼。我也將它作爲新的答案發布。謝謝你的幫助! –

+0

如果這就是你最終做的你應該將其標記爲你接受的答案,而不是馬特的答案。 –

回答

0

編輯:殺手實際上是我的觀點的背景顏色是alpha 0.8透明。一旦我使它變得不透明(alpha = 1.0),動畫就順利了!


我修改了代碼只在動畫完成後,使文本框的焦點。

CGPoint c = thepoint; 
CGFloat tx = c.x - floorf(theview.center.x) + 10; 
CGFloat ty = c.y - floorf(theview.center.y) + 100; 

[UIView animateWithDuration:0.5 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        // Transforms 
        CGAffineTransform t = CGAffineTransformMakeTranslation(tx, ty); 
        t = CGAffineTransformScale(t, 0.1, 0.1); 
        theview.transform = t; 
        theview.layer.masksToBounds = YES; 
        [theview setTransform:CGAffineTransformIdentity]; 

       } 
       completion:^(BOOL finished) { 
        if(theview.tag == 1000) { 
         if(myVC != nil) 
          [myVC focusCommentText]; /// Here is where I set focus 
        } 
       }]; 

CATransition使用,它是委託animationDidStop我必須選擇。

CATransition *transition = [CATransition animation]; 
    transition.duration = 0.4; 
    transition.type = kCATransitionFromRight; //choose your animation 
    transition.subtype = kCATransitionFade; 
    transition.delegate = self; //Setting Delegate as Self 

    [self.view.layer addAnimation:transition forKey:nil]; 
    [self.view addSubview:myVC.view]; 


#pragma mark - CATransition Delegate 
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag 
{ 
    if(myVC != nil) { 
     [myVC focusCommentText]; 
    } 
} 
1

我會做的是後呼叫[textView becomeFirstResponder]直到的過渡已經完成

+0

謝謝!我修改了我的代碼,使其專注於** Animation **的完成**和** CATransition **我在代理'animationDidStop'中實現了相同的功能 –