我有一个应用程序,底部有一个可拖动的UIView.可拖动的视图不完全在屏幕外,并且具有用户可以向上或向下拖动的"拉片".向上和向下拖动当前有效,但我想给它与Apple通知滑出抽屉相同的行为.
例如,如果我将视图向上拖出50%并从屏幕上移开我的手指,那么我希望可拖动的视图继续向上移动.同样,如果用户仅将视图拖出,例如向上30%,则视图应该回落到其默认位置.
理想情况下,虽然我可以上下拖动,但动作并非"有机"......
现在,我正在通过UIPanGestureRecognizer完成向上和向下拖动,以防万一与问题相关.
它是否可能与可拖动视图的Y位置的某些聪明的数学有关,然后用一些CAAnimations进行其余的移动?
可视化可能有点困难,所以我在下面添加了一些屏幕.
谢谢!
iphone core-animation draggable uiview uipangesturerecognizer
我正在我的UIImageView另一个UIView矩形.通过将平移手势应用于UIView矩形,它也可以在外面UIImageView.我不想被拖出去UIImageView
我尝试了下面的代码,但它没有那样工作
-(void)handleMovementView:(UIPanGestureRecognizer *)recognizer
{
CGPoint movement;
if(recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged || recognizer.state == UIGestureRecognizerStateEnded)
{
CGRect rec = recognizer.view.frame;
CGRect imgvw = self.imgViewCrop.frame;
if((rec.origin.x >= imgvw.origin.x && (rec.origin.x + rec.size.width <= imgvw.origin.x + imgvw.size.width)))
{
CGPoint translation = [recognizer translationInView:recognizer.view.superview];
movement = translation;
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointZero inView:recognizer.view.superview];
[self handleMovementForHandlers:movement];
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我慢慢地应用Pan,它会应用这个条件但是当我快速移动时它会超出ImageView
iphone objective-c uiimageview uigesturerecognizer uipangesturerecognizer
我只是做了一个示例来检查平移手势。
平移手势正在检测并且工作正常。
但是每当我在平移手势中给出第二个点时,就像CGPoint secondPoint = [sender locationOfTouch:1 inView:self.imageView];它崩溃了一样。
控制台正在给出消息
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UIPanGestureRecognizer locationOfTouch:inView:]: index (1) beyond bounds (1).'
Run Code Online (Sandbox Code Playgroud)
当我使用panGestureRecognizer.maximumNumberOfTouches = 1;
panGestureRecognizer.minimumNumberOfTouches =1; 它仍然崩溃。
当我使用panGestureRecognizer.maximumNumberOfTouches = 2;
panGestureRecognizer.minimumNumberOfTouches = 2;
时,它没有进入
- (void)panGestureHandler:(UIPanGestureRecognizer *)sender method.
Run Code Online (Sandbox Code Playgroud)
谁能指导我哪里出错了。
预先感谢您。希望您的帮助。
我用这种方式尝试过。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureHandler:)];
panGestureRecognizer.maximumNumberOfTouches = 2;
[self.imageView addGestureRecognizer:panGestureRecognizer];
}
- …Run Code Online (Sandbox Code Playgroud) iphone objective-c uigesturerecognizer ios uipangesturerecognizer
我正在尝试实现一个可以拖出超级视图的UIView.
我尝试添加一个UIPanGestureRecognizer我希望能够拖动的视图.然而,似乎将UIView从其超级视图中移除并将其添加到另一个视图中,正在破坏手势识别器.
使用UIGestureRecognizerStateBegan注释掉的代码,其他两个块中的代码可以正常运行,但是当我恢复它时,永远不会实现UIGestureRecognizerStateChanged和UIGestureRecognizerStateEnded状态.
出了什么问题?
if ([gr state] == UIGestureRecognizerStateBegan)
{
CGPoint newCenter = [endView convertPoint:[self center]
fromView:startView];
[self removeFromSuperview];
[endView addSubview:self];
[self setCenter:newCenter];
}
if ([gr state] == UIGestureRecognizerStateChanged)
{
// Some code that successfully moves the view.
}
if ([gr state] == UIGestureRecognizerStateEnded)
{
// Other code.
}
Run Code Online (Sandbox Code Playgroud) ScrollView有一些SubViews ....
ScrollView包含其预定义的手势(Pan)和我的自定义手势(Pan)以及同时识别它...
SubViews还包含自定义Pan Gesture ......
一切正常SubViews上的平移手势很好...
当我在SubView上做平移时它的SuperView也会触及并处理我不想要的东西......
当在subViews上进行平移时,superView不应该识别它们. .
我如何阻止将我的SubView手势传递给SuperView?
I want to make a back swipe like the one in iOS 7.I'm still new with the whole iOS development, this is what I'm currently using.
Currently I have a pan gesture that detects if the user swipes back and then it just pops the navigation controller.
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
-(void)handlePan:(UIPanGestureRecognizer *)sender{
CGPoint tran = [recognizer translationInView:recognizer.view];
CGPoint vel = [recognizer velocityInView:recognizer.view];
if(vel.x > 500 && tran.x > 100){
[self.navigationController popViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
I …
uinavigationcontroller ios uiswipegesturerecognizer uipangesturerecognizer ios7
当使用UIPanGestureRecognizer和检测时UIGestureRecognizerStateEnded,手势的速度不是真正的速度.相反,它是我之前调用我的动作方法的旧速度.如何在手势结束时访问真实速度?
我创建了UIPanGestureRecognizer这样的:
UIPanGestureRecognizer* panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
[panGestureRecognizer setMaximumNumberOfTouches:2];
[panGestureRecognizer setMinimumNumberOfTouches:1];
[panGestureRecognizer setDelegate:self];
[panGestureRecognizer setDelaysTouchesBegan:NO];
[panGestureRecognizer setDelaysTouchesEnded:NO];
[panGestureRecognizer setCancelsTouchesInView:NO];
[self addGestureRecognizer:panGestureRecognizer];
Run Code Online (Sandbox Code Playgroud)
我的动作方法的开头是:
- (IBAction) panGestureRecognized:(UIPanGestureRecognizer *)recognizer {
UIGestureRecognizerState state = recognizer.state;
CGPoint gestureTranslation = [recognizer translationInView:self];
CGPoint gestureVelocity = [recognizer velocityInView:self];
[CBAppDelegate log:@"panGestureRecognized: state: %s\n translation: (%f, %f)\n velocity: (%f, %f)", [self toString:state], gestureTranslation.x, gestureTranslation.y, gestureVelocity.x, gestureVelocity.y];
Run Code Online (Sandbox Code Playgroud)
日志输出示例:
2013-09-30_10:46:32.830 panGestureRecognized: state: UIGestureRecognizerStateChanged
translation: (-283.000000, 2.000000)
velocity: (-43.046783, 45.551472)
2013-09-30_10:47:02.942 panGestureRecognized: state: UIGestureRecognizerStateEnded …Run Code Online (Sandbox Code Playgroud) 
我想限制黑色图像UIView在girlimageview bounds内移动.我不应该移动到girlimageview之外.
我的girlimageview是带框架的静态图像(5,0,310,320)
我正在使用UIGestureRecognizer在imageview上移动黑色图像.
我尝试使用以下代码UIPanGestureRecognizer来限制但无法限制它.
UIPanGestureRecognizer *panTagGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[panTagGesture setDelegate:self];
[blackanimateview addGestureRecognizer:panTagGesture];
-(void) handlePan:(UIGestureRecognizer*)panGes{
CGPoint point = [panGes locationInView:girlimageview];
if (point.x < girlimageview.bounds.size.width) {
CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);
blackanimateview.frame = newframe;
}
if (point.y < girlimageview.bounds.size.height-160) {
CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);
blackanimateview.frame = newframe;
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
objective-c uiimageview uigesturerecognizer ios uipangesturerecognizer
我有一个UICollectionView和一个习惯UICollectionViewCell
我希望能够捕捉到UICollectionView手势UIGestureRecognizerDelegate,实际上我想通过使用此委托的方法来处理一些手势冲突:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
Run Code Online (Sandbox Code Playgroud)
我怎么能抓住它UICollectionView的UIGestureRecognizerDelegate?
iphone uigesturerecognizer ios uipangesturerecognizer uicollectionview
我有以下层次结构:
这些视图中的每一个都已UIPanGestureRecognizer分配。外部平移手势识别器仅对垂直平移感兴趣,因此我为此实现了委托方法:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint velocity = [panGestureRecognizer velocityInView:panGestureRecognizer.view];
return fabs(velocity.y) > fabs(velocity.x);
}
Run Code Online (Sandbox Code Playgroud)
然而,子视图的平移手势在识别中始终优先。有没有办法让外部平移手势识别器首先识别,然后如果失败,子视图中的平移手势可以接管?
我尝试同时识别并且它有效,但随后两个识别器都开始平移:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
Run Code Online (Sandbox Code Playgroud) ios ×8
iphone ×5
objective-c ×4
uiview ×3
uiimageview ×2
cocoa-touch ×1
draggable ×1
ios7 ×1
superview ×1