views:

31

answers:

1

Hi I have a problem that drives me crazy.

I have a UIImageView in a UIView. The image should be replaced with a flip-animation of the view. So i remove an add a subview in the view. That works fine. But now i am trying to change the image and the frame property of the imageview right befor the animation starts.

The problem is, the changes are not applied. If i add a timer of some milliseconds between the frame-change and the animation start it's applied properly.

- (void)showPage:(int)index {
    [self newViewForImageIndex:index];
    [NSTimer scheduledTimerWithTimeInterval:.02f target:self selector:@selector(animate:) userInfo:nil repeats:NO];
}

- (void)newViewForImageIndex:(int)index {

    UIImageView *oldImage = (UIImageView*)[images objectAtIndex:index];
    float yLoc = oldImage.frame.origin.y - scrollView.contentOffset.y;    
    detailViewController.newImage.frame = CGRectMake(0, yLoc, 150, 100);
    detailViewController.newImage.image = oldImage.image;

}

- (void)animate:(id)sender {    

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:detailViewController.containerView cache:YES];
    [detailViewController.newImage removeFromSuperview];
    [detailViewController.containerView addSubview:detailContent];

    detailViewController.view.alpha = 1.0f;
    detailViewController.containerView.frame = detailContent.frame;

    [UIView commitAnimations];
}

This version works. But if i'd call animate: directly after newViewForImageIndex: without the timer, the changes in the newView..-method are not applied.

Could someone explain why that is? and is there a way to do this without the timer?

thx

A: 

This could be a threading issue. You could try calling newViewForImageIndex on main thread and with waitUntilDone: YES then call animate.

  • (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
jamihash