Reputation: 17591
I have two imageViews that I call firstView and secondView; I have to do an animation that move a third imageView that I call imageView3. This imageView3 is inside firstView and I do this code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[imageView3 setFrame:frameinSecondView];
[UIView commitAnimations];
//[imageView3 removeFromSuperview];
//[secondView addSubview:imageView3];
with this code I can move imageView3 to secondView but the problem is that I'm not able to set imageView3 in the correct frame "frameinSeconView"; instead if I use the commented code
[imageToMove removeFromSuperview];
[scrollViewAlfabeto addSubview:imageToMove];
imageView3 go on the correct frame but I don't see the animation because when it starts its animation, imageview3 disappear from firstView ad appear when it go on secondView
How Can I solve to have a correct animation, with a correct frame between these two imageViews.
Upvotes: 0
Views: 1592
Reputation: 377
You are trying to pass imageView3 from 1 to 2 right? Remove it from imageView1 and place it on the windowView, do the animation from 1 to 2 and wait to end the animations to remove from windowView and insert into imageView2
how to wait? ... well there is a [sentence something] structure that do that, but i dont know how is it, instead of that (cause ive never found how) i started to use "animation blocks" :D
what is an animation block? block: object that means an action; below is an example of an animation using block objects block1, block2 (CODE PARTC)
[UIView animateWithDuration:2 delay:0
options:UIViewAnimationCurveEaseIn
animations: block1
completion: block2
];
It means that it will do actions defined in block1, as if they were inside begin-commit animation sentences, and (the beautiful part) after its COMPLETION they will do the actions in block2! :D!
but what is a f----ng block?; well... THIS IS A F----NG BLOCK!:
Block that returns void (CODE PARTA):
void (^block1)(void) = ^{
centerPortrait.frame = frame1;
if (lookingMenu==NO)
listTableView.frame = frameT1;
};
Block that returns BOOL (after completion: you need a bool) and that have another animation inside (CODE PARTB)
void (^block2)(BOOL) = ^(BOOL got){
[UIView animateWithDuration:halfDuration delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
centerPortrait.image = image;
centerPortrait.frame = frame2;
if (lookingMenu==YES)
listTableView.frame = frameT2;
}
completion:nil
];
};
I've used this to make a fake rotation of an image hohohoho Anyways if u didnt got it, the order is PARTA,B,C :P
is where i got how to use blocks :D, and heres an useful tutorial of the great RAYWENDERLICH: http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial
Hope it helps!
Upvotes: 1