Is this a frame issue?

Discussion in 'iOS Programming' started by beardedpig, Mar 13, 2009.

  1. beardedpig macrumors member

    Joined:
    Dec 17, 2008
    #1
    I have an imageview set to take up the entire screen.

    On top of that I have another small imageview which I am making moveable via the touchesMoved method.

    This works a treat as each call sets the center value to the new coords and the image moves smoothly.

    But what happens is as the moveable image moves it keeps flashing to the top left of the screen so as if appearing twice. If I release while it appears at top left that is where it stays?

    Both images are loaded from a nib so think is this a frame problem and if so can someone explain it for me please?

    If the small image exists inside the big image which takes up full screen surely the frame defaults to the layout?

    Thanks
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    Seems rather odd behaviour; could you post the relevant parts of touchesMoved so we can see what's going on?
     
  3. beardedpig thread starter macrumors member

    Joined:
    Dec 17, 2008
    #3
    sure.

    Just recreated a brand new app creating the views etc in code, no nib, and still get a doubling effect!!! grr

    Code:
    -(void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
    {
    	UITouch *touch = [touches anyObject];
    	
    		CGPoint location = [touch locationInView:self];
    		self.center = location;		
    
    }
    
     
  4. beardedpig thread starter macrumors member

    Joined:
    Dec 17, 2008
    #4
    Could someone explain if I am completely off beam here please?

    I create an imagview and set the frame like so:

    Code:
    appRect = [[UIScreen mainScreen] applicationFrame];
    contentView = [[UIImageView alloc] initWithFrame: appRect];
    
    Then set the origin like so:

    Code:
    appRect.origin = CGPointMake(0.0f, 0.0f);
    
    then I create another imageview to sit inside the first like so:

    Code:
    	
    myView = [[MoveableImage alloc] initWithFrame: CGRectInset(appRect, 20.0f, 20.0f)];
    
    MoveableImage is a class based on UIImageView that I am using to code the touch methods.

    So I now have a base imageview and another one sitting inside it offset to 20,20

    Now I want to detect the user dragging the inset imageview and move it to the new location like so:

    Code:
    -(void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
    {
    	UITouch *touch = [touches anyObject];
    	
    	CGPoint location = [touch locationInView:self];
    		
    	[self setFrame: CGRectMake(location.x, location.y, self.image.size.width, self.image.size.height)];
    }
    
    Now never mind at the moment that the coords will make the image jump
    to the new location, Ill deal with the calculating later.

    What I get is the imageview moves as I drag it but I also get what I would describe as a ghosting of the imageview jumping about like maybe cocoa is trying to be too clever and adjust something I am doing and so it is drawing the imagview where it thinks it should be at the same time I am drawing.


    Does anyone know what this is and how I can stop it?

    Thanks
     
  5. beardedpig thread starter macrumors member

    Joined:
    Dec 17, 2008
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Ah. Care to fill us in? In case anyone else has a similar issue.
     
  7. beardedpig thread starter macrumors member

    Joined:
    Dec 17, 2008
    #7
    Sure:


    Code:
    -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
    {
    	UITouch *touch = [touches anyObject];
    	
    	startPoint = [touch locationInView:self];	
    }
    
    -(void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
    {
    	UITouch *touch = [touches anyObject];
    	
    	CGPoint currentPoint = [touch locationInView:self];
    
    	CGPoint newCentre;
    	
    	CGPoint tempPoint;
    	
    	tempPoint.x = currentPoint.x - startPoint.x;
    	
    	tempPoint.y = currentPoint.y - startPoint.y;
    	
    	newCentre.x = self.center.x + tempPoint.x;
    	
    	newCentre.y = self.center.y + tempPoint.y;
    	
    	self.center = newCentre;
    }
    		
    
     

Share This Page