当KeyBoard出现iOS时,查看过渡结结巴巴

时间:2014-03-24 20:22:24

标签: ios ipad ios7 uiviewanimationtransition

以下是我从ViewA中显示ViewB的转换代码

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) {

    }
}

过渡和键盘即将发生..同时发生..现在它有点尴尬。有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:1)

我要做的是致电[textView becomeFirstResponder],直到过渡

答案 1 :(得分: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];
    }
}