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

BarryK88

macrumors member
Original poster
Mar 1, 2011
31
0
I got several images within my view. When i rotate my device I'd like to have my images being translated with the CGAffineTransformTranslate method so that the images are placed properly within my Landscape View. After I rotate back to Portrait the opposit translation needs to take place.

The translation works so far. However the translation is also being done when I touch and drag the image. How can I make sure that the translation only works on rotation and not with touch and drag.

Here's a part of my code so far:

Code:
-(void) touchesMoved: (NSSet *)touches withEvent: (UIEvent *) event {
		
		UITouch *touch = [[event allTouches] anyObject];
		CGPoint location = [touch locationInView:self.view];
		
		
		if ([touch view] == image1) {
			
			image.center = location;		
			
		}
[super viewDidLoad];
}

-(void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation  {
	
	if(fromInterfaceOrientation == UIInterfaceOrientationPortrait ||
	   fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
			image1.transform = CGAffineTransformTranslate(image1.transform, -64, 145);
}

if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
	   fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
		image1.transform = CGAffineTransformTranslate(image1.transform, 64, -145);
}
Hope someone got an answer this is bothering me all day long. Thanks in advance
 
Last edited by a moderator:
Why are you calling [super viewDidLoad] in your touchesMoved:withEvent: method? You only ever want to make that call in your UIViewController subclass' viewDidLoad and it should only be called once each time the view is loaded from a nib or after loadView is called.
 
Hi thanks for your advice. I'm pretty new to the whole programming of Xcode...

However I still can't figure out how to implement the right code for my needs. Strange thing is that when I'm in Portrait-view the entire drag & drop function works but when I change to Landscape-view the problems appears.
 
Fixed this problem by using

Code:
if ([touch view] == image1) {
		[COLOR="Red"]image1.transform = CGAffineTransformIdentity;[/COLOR]
		image1.center = location;
		
	}
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.