
有些迷失在这里,任何教程还是什么?
谢谢
编辑:在UIScrollVIEw里面有一些代码,它的一个UIImageVIEw,我需要拖动整个滚动条,或者拖动它的内部图像:
_myScroll = [[UIScrollVIEw alloc] initWithFrame:CGRectMake(0,self.window.bounds.size.wIDth,self.window.bounds.size.height)]; [_myScroll setContentSize:CGSizeMake(self.window.bounds.size.wIDth,1300)];_tutorial = [[UIImageVIEw alloc] initWithFrame:CGRectMake(0,1300)]; [_tutorial setimage:[UIImage imagenamed:@"Default"]];_tutorial.contentMode = UIVIEwContentModeScaleAspectFit; [_myScroll addSubvIEw:_tutorial];_tutorial.userInteractionEnabled = YES; UIPanGestureRecognizer * recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:_tutorial action:@selector(handlePan:)]; [_tutorial addGestureRecognizer:recognizer]; [self.window addSubvIEw:_myScroll];
并且我尝试拖动UIImageVIEw的方法
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInVIEw:_myScroll]; recognizer.vIEw.center = CGPointMake(recognizer.vIEw.center.x + translation.x,recognizer.vIEw.center.y + translation.y); [recognizer setTranslation:CGPointMake(0,0) inVIEw:_myScroll];}解决方法 看看 here.这是一个UIGestureRecognizer教程,它将为您提供处理捏和平移手势的基础知识.一旦了解了基础知识,就可以很容易地完成你想要的工作.所有您需要的是在平移完成后检查视图的位置以将其发送到正确的位置.看看UIScrollVIEws上的 this other tutorial,它可能会帮助你找到你的方式通过第二部分. 这两个教程来自raywenderlich.com,可能是我认识的最有用的iOS教程网站.
以下是您可以处理的handlePan:方法的一些代码:
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInVIEw:_myScroll]; recognizer.vIEw.center = CGPointMake(recognizer.vIEw.center.x + translation.x,recognizer.vIEw.center.y + translation.y); if (recognizer.state == UIGestureRecognizerStateEnded) { // Check here for the position of the vIEw when the user stops touching the screen // Set "CGfloat finalX" and "CGfloat finalY",depending on the last position of the touch // Use this to animate the position of your vIEw to where you want [UIVIEw animateWithDuration: aDuration delay: 0 options: UIVIEwAnimationoptionCurveEaSEOut animations:^{ CGPoint finalPoint = CGPointMake(finalX,finalY); recognizer.vIEw.center = finalPoint; } completion:nil]; } [recognizer setTranslation:CGPointMake(0,0) inVIEw:_myScroll];} 我不会给你完美的答案在这里,你必须在代码上找到一种方法,使其工作,你想要它.
这是最后一个提示.您可以使用slIDeFactor做一些“平滑”动画.它将帮助您的动画更“现实”.在这个代码上工作,你在“if”开头添加的代码:
CGPoint veLocity = [recognizer veLocityInVIEw:self.vIEw];CGfloat magnitude = sqrtf((veLocity.x * veLocity.x) + (veLocity.y * veLocity.y));CGfloat slIDeMult = magnitude / 200;float slIDeFactor = 0.1 * slIDeMult; // Increase for more slIDe
然后在UIVIEw animateWithDuration :,使用slIDeFactor作为持续时间.
总结以上是内存溢出为你收集整理的ios – UIGestureRecognizer拖动UIView全部内容,希望文章能够帮你解决ios – UIGestureRecognizer拖动UIView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)