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

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
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
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Seems rather odd behaviour; could you post the relevant parts of touchesMoved so we can see what's going on?
 

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
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;		

}
 

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
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
 

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
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;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.