如何用手指在iphone中移动视图Objective-c

Ami*_*hel 4 iphone cocoa-touch objective-c touch swipe

我有这个观点,他的大小是1280 X 345,我在屏幕上左右移动它.现在,我的主要问题是我如何用手指移动(不是swipeLeft/swipeRight)我希望它像iPhone IOS的​​主屏幕一样用我的手指移动.

现在,即时通讯使用此代码:

- (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);
}
Run Code Online (Sandbox Code Playgroud)

这应该是目前的方式,但我不能说出来.我也尝试在谷歌和这里找到答案,但是,如你所知..我没有找到有用的东西.

我也做了这个,所以你可以更好地理解它.

在此输入图像描述

Jim*_*Jim 8

不要自己编写代码来执行此操作.使用UIScrollView.这就是它的设计目标.