Animations sur une entrée de vue

septembre 2010 modifié dans Objective-C, Swift, C, C++ #1
Bonjour à  tous,

J'ai un léger problème sur Mac OS X pour effectuer 2 animations respectivement sur 2 vues différentes.

La vue appelée "firstView" est ajoutée par défaut au lancement de l'application.
J'utiliser performSelector:withObject:afterDelay: pour effectuer l'animation X secondes après lancement de l'application (simple test).
Au moment où la méthode "switchToView:" est appelée, j'ajoute "secondView" et c'est là  que je désire faire un scale sur les 2 vues en question.

<br /><br /><br />- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {<br />	<br />	firstView.frame = [[window contentView] frame];<br />	[[window contentView] addSubview:firstView];<br /><br />	[self performSelector:@selector(switchToView:) withObject:secondView afterDelay:2.0];<br />	<br />	<br />}<br /><br />- (void)switchToView:(NSView*)anotherView<br />{<br />	// Ajout de la sconde vue dans la contentView<br />	anotherView.frame = [[window contentView] frame];<br />	[[window contentView] addSubview:anotherView];<br />	<br />	// setWantsLayer sur les 2 vues<br />	[firstView setWantsLayer:YES];<br />	[anotherView setWantsLayer:YES];<br />	<br /><br />	<br />	// Récupération des CALayer<br />	CALayer* firstViewLayer = firstView.layer;<br />	CALayer* secondViewLayer = anotherView.layer;<br /><br /><br />	// Animation de la première vue, amenée à  disparaà®tre via un scale<br />	CABasicAnimation *firstViewAnimation;<br />	<br />	firstViewAnimation=[CABasicAnimation animationWithKeyPath:@&quot;transform.scale&quot;];<br />	firstViewAnimation.duration=1.0;<br />	firstViewAnimation.autoreverses=NO;<br />	firstViewAnimation.fromValue=[NSNumber numberWithFloat:1.0];<br />	firstViewAnimation.toValue=[NSNumber numberWithFloat:0.1];<br />	<br />	// Animation de la seconde vue, amenée à  apparaà®tre via un scale<br />	CABasicAnimation *secondViewAnimation;<br />	<br />	secondViewAnimation=[CABasicAnimation animationWithKeyPath:@&quot;transform.scale&quot;];<br />	secondViewAnimation.duration=1.0;<br />	secondViewAnimation.autoreverses=NO;<br />	secondViewAnimation.fromValue=[NSNumber numberWithFloat:3.0];<br />	secondViewAnimation.toValue=[NSNumber numberWithFloat:1.0];<br />	<br />	<br />	// Ajout des 2 anims dans leur CALayer respectifs<br />	[firstViewLayer addAnimation:firstViewAnimation forKey:@&quot;animateFirstView&quot;];<br />	[secondViewLayer addAnimation:secondViewAnimation forKey:@&quot;animateSecondView&quot;];<br />	<br /><br />}<br />

Le problème qui se pose est que je n'ai qu'un simple fade-in.
J'ai trouvé qu'en retirant [firstView setWantsLayer:YES];, j'obtiens l'effet escompté.


Un peu d'aide ne serait donc pas de refus, car j'ai pour l'instant du mal à  cerner le problème

Réponses

  • 05:14 modifié #2
    ça n'a pas bousculé grand monde !
    Le problème a été résolu après avoir regardé plusieurs exemple made-in Apple.
    Il y a cependant certains bugs graphiques quand j'effectue l'animation sur une tableView, donc j'ai opté pour une seconde méthode, celle de remplacer, juste avant l'animation, les 2 vues par leurs images.

    <br /><br />- (void)_pushView:(NSView*)aNewView fromView:(NSView*)aView<br />{<br />	[self _abortAnimationAndResetViews];<br /><br />	/** Setup old layer if exists */<br />	CALayer* oldLayer =nil;<br />	<br />	if([aView superview]!=nil)<br />		oldLayer = [CALayer layer];<br />	<br />	if(oldLayer){<br />		oldViewBeingAnimated = [[NSView alloc] initWithFrame:[aView frame]];<br />		[oldViewBeingAnimated setWantsLayer:YES];<br />		[[aView superview] addSubview:oldViewBeingAnimated];<br />		<br />		NSBitmapImageRep* oldRep = [aView bitmapImageRepForCachingDisplayInRect:[aView visibleRect]];<br />		[aView cacheDisplayInRect:[aView visibleRect] toBitmapImageRep:oldRep];<br />		oldLayer.frame = [oldViewBeingAnimated layer].frame;<br />		<br />		[aView removeFromSuperview];<br /><br />		oldLayer.opacity= 1.0;<br />		oldLayer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0);<br />		oldLayer.contents = (id)[oldRep CGImage];<br />		[[oldViewBeingAnimated layer] addSublayer:oldLayer];<br />		<br />		<br />		/** Setup group animation for the old layer */<br />		CAAnimationGroup* oldGroupAnim = [CAAnimationGroup animation];<br />		oldGroupAnim.duration = kGlobalAnimationDuration;<br />		oldGroupAnim.delegate=self;<br />		oldGroupAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];<br />		CABasicAnimation *oldAnimScale = [CABasicAnimation animationWithKeyPath:@&quot;transform&quot;];<br />		oldAnimScale.fromValue = [NSValue valueWithCATransform3D:oldLayer.transform];<br />		oldLayer.transform = CATransform3DMakeScale(1.3, 1.3, 1.0);<br />		CABasicAnimation *oldAnimFade = [CABasicAnimation animationWithKeyPath:@&quot;opacity&quot;];<br />		oldAnimFade.fromValue = [NSNumber numberWithFloat:1.0];<br />		oldLayer.opacity = 0.0;<br />		[oldGroupAnim setAnimations:[NSArray arrayWithObjects:oldAnimScale, oldAnimFade,nil]];<br />		<br />		[oldLayer addAnimation:oldGroupAnim forKey:@&quot;transform&quot;];<br /><br />	}<br />	<br /><br />}<br /><br />
    


    J'ai trouvé un exemple du genre dans la doc Apple où une NSWindow apparaissait avec un scale. La contentView était remplacée par son image.

Connectez-vous ou Inscrivez-vous pour répondre.