Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to move view with my finger in iphone Objective-c

i have this view that the size of him is 1280 X 345 and im moving it left and right in my screen. now, my main question is how do i make it move with my finger (not swipeLeft / swipeRight) i want it to move with my finger like the home screen of the iPhone IOS.

now, im using this code:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:infoView];
    //[self.view setTransform:CGAffineTransformTranslate(CGAffineTransformIdentity, (location.x + self.view.frame.origin.x - dx), 0.0)];
    NSLog(@"touch: %f",location.x);

    infoView.frame = CGRectMake(infoView.frame.origin.x + location.x, 0, 1280, 345);
}

that should be the current way but i cant figur it out. i have also try to find an answer in google and here, but, as you know.. i didn't found something useful.

i've also made this so you can understand it better.

enter image description here

like image 385
Amir Foghel Avatar asked Feb 21 '23 17:02

Amir Foghel


1 Answers

Don't write code to do this yourself. Use UIScrollView. This is what it is designed for.

like image 131
Jim Avatar answered Mar 05 '23 05:03

Jim