Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
317
11
* NOTE : (not animated ScrollView)

Hi all.

I have a bunch of views in a scrollview. and the current (lets call it a card)
has animation on it.

But by the time all the views have drawn on the Scrollview, I seem to miss the Animation.

How do I best sync the Drawing of the scrollview and the Animated View?

thanks
Ian

ps. Using to Animate:

Code:
CAAnimationGroup *animGroupp = [CAAnimationGroup animation];	

// Scroll view is being populated in: 
- (void)viewDidLoad

// would viewWillApear be better ??
-(void)viewWillAppear:(BOOL)animated
 
You add your stuff to the view in the viewDidLoad (that's when the XIB/NIB is loaded in, or your view is loaded).
When the user actually sees the view, that's the viewWillAppear, so put it in there ^_^
Or do delayed performSelector in the viewDidLoad if you only want the animation once. or work with bools
 
course -solution.

Thanks all.

My Course solution since there is only one view animating ever is to scroll to that view on view:

Code:
-(void)viewWillAppear:(BOOL)animated
{
   // other stuff .... 
 
 [self.scrollView scrollRectToVisible:frame animated:YES];
}

now I need just add and subtract views..

What would be uber-cool would be to animate the insertion or deletion of the views... any hints.. ???/

thanks
Ian
 
give each view a tag when you generate them, and when you press delete, just fade out the view with the tag give in a special method, like fade out, and rest just animates .y value - the height of 1 view..
 
thanks

Is it bad form to use "notification centre" to signal the view controller to update the ScrollView. or maybe a flag? what's the best practice??/

also I would like to animate the views on the scrollview like "fade out the view" then animate the other views sliding in to where the "deleted" view was.

or in scrollView the new view into the place the old view was..

[view][deleted view][new view]
[view][Magic animation poof][new view]
[view][Magic anima<<<][new view]
[view][Magic<<][new view]
[view][new View]

something like that or reverse of that. What's the easiest way to achieve that? transitions?

thanks.
Ian

ps. How can I add a view to (0,0) beginning of the scrollview?
or do I rebuild the scrollview and then switch to the (old bustedview)

p.s^2... then I could show current view (old busted) and animate to (new cool view) .. would that work?

p.s^3 .. for pushing a view on the top/front of scrollview..


Ok that almost works but for some reason my Navigation Controller is getting triggered by

Code:
 [scrollView setContentOffset:CGPointMake(0,0) animated:YES];
 
Last edited:
answering my own question.

Just animate the view Away.. by the size of the View.

Code:
-(void)viewToMoveTag:(UIView *)viewMoving insert:(BOOL)inserting durationTiming:(CGFloat)duration
{
	CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    
	NSLog(@"To: %f from: %f",frame.origin.x, viewMoving.frame.origin.x);
	
	// Setup the animation
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:duration];
	//[UIView setAnimationCurve:curve];
	[UIView setAnimationBeginsFromCurrentState:YES];
	
	// The transform matrix
	// inserting = YES then will move the current view Left and create a space for  one Card// 
	// inserting = NO then the card 
	
	if (!inserting) {
		CGAffineTransform transform = CGAffineTransformMakeTranslation(-1*viewMoving.frame.size.width,0);
		viewMoving.transform = transform;
		// Commit the changes //
		[UIView commitAnimations];

	}
	
	if (inserting) {
		CGAffineTransform transform = CGAffineTransformMakeTranslation(viewMoving.frame.size.width,0);
		viewMoving.transform = transform;
		// Commit the changes //
		[UIView commitAnimations];
		
	}
}

Sorry about the formatting.. '

Hope this helps someone..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.