UIView animation problem
Posted
by
FoJjen
on Stack Overflow
See other posts from Stack Overflow
or by FoJjen
Published on 2011-01-07T00:50:55Z
Indexed on
2011/01/07
0:53 UTC
Read the original article
Hit count: 229
iphone
|uiviewanimation
I try to make a UIImageView open like a hatch, and under the "hatchView" its anoter imageView but when I start the animation its like the view under gets over and cover the animation, When the animation gets over the imageView the its getting visibel. its works fine if a remove the imageView thats under.
Here is the code for animation view.
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *) event {
if (!isHatchOpen) {
if (hatchView.layer.anchorPoint.x != 0.0f) {
hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y);
}
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:hatchView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
float pct = location.x / 320.0f;
float rad = acosf(pct);
CATransform3D transform = CATransform3DMakeRotation(-rad+5, 0.0f, -1.0f, 0.0f);
transform.m14 = (1.0 / -2000) * acosf(pct);
hatchView.layer.transform = transform;
[UIView commitAnimations];
isHatchOpen = YES;
} else {
if (hatchView.layer.anchorPoint.x != 0.0f) {
hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y);
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationBeginsFromCurrentState:YES];
CATransform3D transform = CATransform3DMakeRotation(0, 0.0f, -1.0f, 0.0f);
transform.m14 = 0;
hatchView.layer.transform = transform;
// Commit the changes
[UIView commitAnimations];
isHatchOpen = NO;
}
}
And here a add the Views
hatchView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, frame.size.width-1, frame.size.height-2)];
[self addSubview:hatchView];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, frame.size.width-2, frame.size.height-2)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self insertSubview:imageView belowSubview:hatchView];
© Stack Overflow or respective owner