Here is a transition code I have for Showing ViewB from ViewA
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) {
}];
Now that the transition went very smooth without issues.
When in my ViewB, I had a text box with default focus. (In 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) {
}
}
The Transition and the Keyboard coming up.. happens at same time.. And it is slightly awkward now. Can some one help me out here please?
EDIT: The killer was actually the background color of my view was transparent with alpha 0.8. Once I made it opaque (alpha = 1.0), the animation was smooth!!
I modified my code to make the focus of text box only after completion of the animation.
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
}
}];
When CATransition
is used, it is the delegate animationDidStop
I have to choose.
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];
}
}