Partage
  • Partager sur Facebook
  • Partager sur Twitter

{{Titre incorrect}} Objective C IOS 5

Insertion d'objets custom dans une application

Sujet résolu
    29 mars 2012 à 10:54:19

    Bonjour,

    Je tente actuellement de réaliser une application sur IOs avec une vue dynamique ressemblant à l'interface principale de l'iphone. Je travaille pour l'instant sur la dynamique des icones.

    J'ai créé une classe héritant de UIView et définissant les méthodes d'animation des icones (qui sont des objets de type UIButton) en m'inspirant du sample code Move Me du site apple developer. Je suis sur Xcode 5 et j'ai donc aussi un VIewController auquel j'ai ajouté les objets en question en essayant de les renommer pour qu'ils acquièrent les propriétés de ma vue et de mes icones. Le code bug car apparemment il n'arrive pas à trouver les propriétés de mon objet de classe vueGenerale (heritant de UIView) sur une question de coordonnées (ce qui est étonnant pour un objet de type UIView). Je pense que c'est plus une question de structure qu'une erreur dans le contenu du code. J'ai du mal comprendre un aspect de la structuration des classes sans savoir lequel.

    pouvez vous m'éclairer sur les erreurs de mon code, car cela fais deux jours que je tourne dans la doc apple sans trouver de solution à ce problème.

    Voici mon code; merci d'avance



    vueGenerale.h


    </code>
    #import <UIKit/UIKit.h>
    #import "ViewController.h"
    
    extern UIButton *bouton01;
    
    @interface vueGenerale : UIView 
    
    
    + (void)animateFirstTouchAtPoint:(CGPoint)touchPoint; 
    + (void)animateVueGeneraleToCenter;
    - (void)growAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
    @end
    
    
    
    vueGenerale.m
    
    
    
    
    
    #import "vueGenerale.h"
    #import <QuartzCore/QuartzCore.h>
    
    @implementation vueGenerale
    
    #define GROW_ANIMATION_DURATION_SECONDS 0.15
    #define SHRINK_ANIMATION_DURATION_SECONDS 0.15
    
    
    
    - (void)growAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:SHRINK_ANIMATION_DURATION_SECONDS];
        bouton01.transform = CGAffineTransformMakeScale(1.1, 1.1);	
        [UIView commitAnimations];
    }
    
    
    
    - (void)animateFirstTouchAtPoint:(CGPoint)touchPoint {
        
    	[UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:GROW_ANIMATION_DURATION_SECONDS];
    	[UIView setAnimationDelegate:self];
    	[UIView setAnimationDidStopSelector:@selector(growAnimationDidStop:finished:context:)];
    	CGAffineTransform transform = CGAffineTransformMakeScale(1.2, 1.2);
    	bouton01.transform = transform;
    	[UIView commitAnimations];
    	
    	[UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:GROW_ANIMATION_DURATION_SECONDS + SHRINK_ANIMATION_DURATION_SECONDS];
    	bouton01.center = touchPoint;
    	[UIView commitAnimations];
    }
    
    
    - (void)animateVueGeneraleToCenter {
    	
    	// Bounces the placard back to the center
        
    	CALayer *welcomeLayer = bouton01.layer;
    	
    	// Create a keyframe animation to follow a path back to the center
    	CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    	bounceAnimation.removedOnCompletion = NO;
        
    	CGFloat animationDuration = 1.5f;
        
    	
    	// Create the path for the bounces
    	CGMutablePathRef thePath = CGPathCreateMutable();
    	
    	CGFloat midX = self.center.x;
    	CGFloat midY = self.center.y;
    	CGFloat originalOffsetX = bouton01.center.x - midX;
    	CGFloat originalOffsetY = bouton01.center.y - midY;
    	CGFloat offsetDivider = 4.0f;
    	
    	BOOL stopBouncing = NO;
    	
    	// Start the path at the placard's current location
    	CGPathMoveToPoint(thePath, NULL, bouton01.center.x, bouton01.center.y);
    	CGPathAddLineToPoint(thePath, NULL, midX, midY);
    	
    	// Add to the bounce path in decreasing excursions from the center
    	while (stopBouncing != YES) {
    		CGPathAddLineToPoint(thePath, NULL, midX + originalOffsetX/offsetDivider, midY + originalOffsetY/offsetDivider);
    		CGPathAddLineToPoint(thePath, NULL, midX, midY);
            
    		offsetDivider += 4;
    		animationDuration += 1/offsetDivider;
    		if ((abs(originalOffsetX/offsetDivider) < 6) && (abs(originalOffsetY/offsetDivider) < 6)) {
    			stopBouncing = YES;
    		}
    	}
    	
    	bounceAnimation.path = thePath;
    	bounceAnimation.duration = animationDuration;
    	CGPathRelease(thePath);
    	
    	// Create a basic animation to restore the size of the placard
    	CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
    	transformAnimation.removedOnCompletion = YES;
    	transformAnimation.duration = animationDuration;
    	transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    	
    	
    	// Create an animation group to combine the keyframe and basic animations
    	CAAnimationGroup *theGroup = [CAAnimationGroup animation];
    	
    	// Set self as the delegate to allow for a callback to reenable user interaction
    	theGroup.delegate = self;
    	theGroup.duration = animationDuration;
    	theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    	
    	theGroup.animations = [NSArray arrayWithObjects:bounceAnimation, transformAnimation, nil];
    	
    	
    	// Add the animation group to the layer
    	[welcomeLayer addAnimation:theGroup forKey:@"animatePlacardViewToCenter"];
    	
    	// Set the placard view's center and transformation to the original values in preparation for the end of the animation
    	bouton01.center = self.center;
    	bouton01.transform = CGAffineTransformIdentity;
    }
    
    
    - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
    	//Animation delegate method called when the animation's finished:
    	// restore the transform and reenable user interaction
    	bouton01.transform = CGAffineTransformIdentity;
    	self.userInteractionEnabled = YES;
    }
    
    
    
    
    
    
    
    ViewController.h
    
    
    
    #import <UIKit/UIKit.h>
    #import "vueGenerale.h"
    
    
    @class vueGenerale;
    
    
    @interface ViewController : UIViewController
    
    @property (weak, nonatomic) IBOutlet vueGenerale *vueGenerale;
    
    @end
    
    
    
    
    
    ViewController.m
    
    
    
    
    #import "ViewController.h"
    #import <QuartzCore/QuartzCore.h>
    #import "vueGenerale.h"
    
    
    @class vueGenerale;
    
    
    @implementation ViewController
    @synthesize vueGenerale;
    
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Release any cached data, images, etc that aren't in use.
    }
    
    #pragma mark - View lifecycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {
     
        [self setVueGenerale:nil];
        [super viewDidUnload];
            // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
    	[super viewWillDisappear:animated];
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
    	[super viewDidDisappear:animated];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    	
    	// We only support single touches, so anyObject retrieves just that touch from touches
    	UITouch *touch = [touches anyObject];
    	
    	// Only move the placard view if the touch was in the placard view
    	if ([touch view] != bouton01) {
    		// In case of a double tap outside the placard view, update the placard's display string
    		return;
    	}
    	// Animate the first touch
    	CGPoint touchPoint = [touch locationInView:vueGenerale];
    	[vueGenerale animateFirstTouchAtPoint:touchPoint];
    }
    
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    	
    	UITouch *touch = [touches anyObject];
    	
    	// If the touch was in the placardView, move the placardView to its location
    	if ([touch view] == vueGenerale) {
    		CGPoint location = [touch locationInView:vueGenerale];
    		bouton01.center = location;		
    		return;
    	}
    }
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    	
    	UITouch *touch = [touches anyObject];
    	
    	// If the touch was in the placardView, bounce it back to the center
    	if ([touch view] == bouton01) {
    		// Disable user interaction so subsequent touches don't interfere with animation
    		[vueGenerale animateVueGeneraleToCenter];
    		return;
    	}		
    }
    
    
    
    
    @end
    
    
    <code type="c">
    
    • Partager sur Facebook
    • Partager sur Twitter
      29 mars 2012 à 18:19:57

      J'ai pas très bien compris en fait ton problème, si tu pouvais faire des screenshots du problème parce que là on sait pas trop ce que tu attends à part qu'on corrige ton code.
      Juste petite intuition, c'est pas très bien de combiner des animations de QuartzCore avec les animations UIView, justement ça engendre des coordonnées erronées quand l'animation se termine. Tu devrais plutôt n'utiliser que des UIView Animation, regarde sur cette piste plutôt.
      • Partager sur Facebook
      • Partager sur Twitter
      Si mon aide vous a été utile, merci de mettre le sujet en résolu et mettre mon post en avant. Cheers!
        31 mars 2012 à 15:16:42

        Le message qui suit est une réponse automatique.
        Les réponses automatiques nous permettent d'éviter de répéter de nombreuses fois la même chose, et donc de gagner beaucoup de temps.
        Nous sommes néanmoins ouverts à toute question ou remarque, n'hésite pas à me contacter par messagerie privée à ce sujet.


        Titre du sujet à modifier


        Bonjour,

        Comme son nom l'indique, ce forum est dédié aux problèmes de développements sur smartphones et tablettes. Vous n'êtes pas sans savoir que les modèles sont nombreux et que les développements sont très différents d'un OS à l'autre. Aussi, il est obligatoire d'ajouter une balise au titre de son sujet afin de bien cadrer le problème.

        Exemples de titres corrects :
        • [iPhone] Problème de curseurs
        • [Android] Faire un jeu

        Exemples de titres incorrects :
        • Problème de curseurs
        • Faire un jeu
        • ca marche pa

        Étant donné que ton message est par ailleurs bien présenté, je t'invite à modifier le titre du sujet pour le clarifier.

        De plus, le titre idéal devrait résumer ton problème ou ta question en une petite phrase. Voici quelques liens pour t'aider à choisir au mieux ton titre :


        Comment fait-on pour éditer un titre ?

        Si tu es l'auteur du topic, tu peux uniquement le changer en éditant le premier post du topic à l'aide de l'icône Image utilisateur.

        Attention : merci de modifier ton titre dans les plus brefs délais, sans quoi le sujet sera fermé.

        Merci de ta compréhension :)
        Les modérateurs.
        • Partager sur Facebook
        • Partager sur Twitter
        Pwaite.net > Transfert de crédit téléphonique et monétisation de site web                                                                                        « I am awesome »

        {{Titre incorrect}} Objective C IOS 5

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown