I'm making a view with a draggable image inside. However I'd like the image to be moved within a specific region within my view. I implemented an if-statement within the touchesMoved method. The function works for one orientation (landscape), but when I change the orientation from Landscape to Portrait the bounds of the other orientation is still in use. How can I make sure that the region is defined and working for the Landscape and Portrait View individualy.
Thanks in advance!
Code:
-(void) touchesMoved: (NSSet *)touches withEvent: (UIEvent *) event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown) {
if(location.x > 720) {
location.x = 720;
}
if(location.x < 50) {
location.x = 50;
}
if(location.y > 790) {
location.y = 790;
}
if(location.y < 116) {
location.y = 116;
}
}
if(deviceOrientation == UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight){
if(location.x > 910) {
location.x = 910;
}
if(location.x < 240) {
location.x = 240;
}
if(location.y > 670) {
location.y = 670;
}
if(location.y < 116) {
location.y = 116;
}
}
if ([touch view] == image1) {
image1.center = location;
}
}
Last edited by a moderator: