具有PageCurl转换的UIPageViewController非常适合模拟页面,但默认的GestureRecognizer(UIPanGestureRecognizer)仅响应一个手指事件.我想在其他事件之上添加两个手指事件.
如何将另一个PanGestureRecognizer添加到当前的UIPageViewController实例?这个新的PanGestureRecognizer应该等待两个手指平移触摸,而不会禁用原始的UIPanGestureRecognizer.
如果用户用两个手指而不是一个手指滚动页面,我需要的是一种提升额外自定义事件的方法,但它仍然应该像调用一个手指事件一样滚动页面.
我怎么能在MonoTouch中做到这一点?
提前致谢.
gestures xamarin.ios ios uipangesturerecognizer uipageviewcontroller
我有一个自定义滑块类型的对象,我希望它更有用.目前我使用UIPanGestureRecognizer并translationInView使其工作.它工作得很好,但我想在那里使用某种速度让它感觉更有用.我已经尝试了一些东西,但不能弄清楚如何正确实现速度changedLevel方程.
- (void)panDetected:(UIPanGestureRecognizer *)gesture {
CGPoint swipeLocation = [gesture locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
LevelCounterTableCell *swipedCell = (LevelCounterTableCell *)[self.tableView cellForRowAtIndexPath:indexPath];
if([gesture state] == UIGestureRecognizerStateBegan) {
NSString *originalLevelString = swipedCell.levelNumber.text;
originalLevel = [originalLevelString intValue]; // int originalLevel
}
if ([gesture state] == UIGestureRecognizerStateChanged) {
CGFloat xTranslation = [gesture translationInView:[[gesture view] superview]].x;
CGFloat xVelocity = [gesture velocityInView: [[gesture view] superview]].x;
// Pan threshold is currently set to 8.0.
// 8.0 is a decent level for …Run Code Online (Sandbox Code Playgroud) 我在视图中有手势代码
- (void)rightSwipeHandle:(UIPanGestureRecognizer*)gestureRecognizer{
CGPoint touchBegan;
CGPoint pointEnd;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
CGPoint touchBegan = [gestureRecognizer locationInView: gestureRecognizer.view];
NSLog(@"pointBegan:%@",NSStringFromCGPoint(touchBegan));
}
else if (gestureRecognizer.state == UIGestureRecognizerStateChanged)
{
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded ||
gestureRecognizer.state == UIGestureRecognizerStateCancelled ||
gestureRecognizer.state == UIGestureRecognizerStateFailed)
{
pointEnd = [gestureRecognizer locationInView:gestureRecognizer.view];
NSLog(@"pointEnd:%@", NSStringFromCGPoint(pointEnd));
CGFloat xDist = (pointEnd.x - touchBegan.x);
CGFloat yDist = (pointEnd.y - touchBegan.y);
CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));
NSLog(@"distance:%f", distance);
}
}
Run Code Online (Sandbox Code Playgroud)
但它不能很好地工作,我不知道问题在哪里...如果滑动是从底部到顶部,它计算距离,如果你做相反的事情,它会计算一个很大的不同距离,我不知道'了解
我添加了以下手势识别器:
UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(ViewDragging2:)];
[d2 setMinimumNumberOfTouches:2];
[d2 setMaximumNumberOfTouches:2];
[targetView addGestureRecognizer:d2];
Run Code Online (Sandbox Code Playgroud)
以及在该事件发生时触发的方法是:
-(void)ViewDragging2:(UIPanGestureRecognizer*)sender {
// some point
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:targetView];
}
Run Code Online (Sandbox Code Playgroud)
即使我用两根手指触摸,这也是我一触即发的重点.如何检索第一次和第二次触摸的线?
我正试图vector从一个UIPanGestureRecognizer关于屏幕轴的a Portrait Orientation.我知道我可以获得速度,这是战斗的一半,但我理想地想要获得关于屏幕垂直轴的角度(罗盘度或弧度)的方法.例如,从左下到右上的拖动将是45度角,从上到下将是180度,或从下到上将是0(或360).
这可能吗?它没有方向属性,文档中的翻译解释有点令人困惑.我是否需要手动创建一个中心点(关于我视图的中心),并比较它的起点/终点Pan Touch?我对所需的数学不太了解.
提前致谢!^ _ ^
cocoa-touch objective-c uigesturerecognizer ios uipangesturerecognizer
我有一个UITableView,其单元格是UITableViewCell的子类,它有一个顶部UIView和一个底部UIView,允许顶部UIView在用户拖动他/她的手指时向右和向左移动.
我通过向每个UITableViewCell添加一个平移手势识别器来实现它.很简单的东西.但是我只想要水平平底锅,但是当它打算向上滚动时会检测到整个单元格的垂直平底锅,这会导致UITableView无法移动.
我试图这样做,只有当用户水平摇动他/她的手指超过5px时才会检测到手势,但它似乎没有工作.滚动工作正常,我可以点击单元格,但我在单元格上滑动十次,它可能工作一次.
我无法弄清楚为什么.
相关代码:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer {
if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
NSLog(@"hi");
CGPoint translation = [(UIPanGestureRecognizer *)recognizer translationInView:self];
if (translation.x > 5 || translation.x < -5) {
return YES;
}
else {
return NO;
}
}
else {
return YES;
}
}
- (void)pannedCell:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
_firstTouchPoint = [recognizer translationInView:self];
}
else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint touchPoint = [recognizer translationInView:self];
// Holds the value of how far away from the …Run Code Online (Sandbox Code Playgroud) objective-c uitableview uigesturerecognizer ios uipangesturerecognizer
在iPad中,当您将手指放在屏幕的顶部或底部边缘之外,然后将其拖动到屏幕上时,会显示一个菜单.你知道怎么做这样的事吗?
我使用SWRevealViewController作为侧边栏,我必须使用滑动来处理我的上一个和下一个故事以及侧边栏的边缘平移.
我使用UIScreenEdgePanGestureRecognizer而不是PanGestureRecogniser的原因是因为滑动会导致调用平移手势,导致整个页面变得混乱.我希望有一种方法可以在边缘泛声识别器激活时调用平移手势而不是使用它:
[self.view addGestureRecognizer:[MainViewController sharedInstance].revealViewController.panGestureRecognizer];
[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: left];
[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: right];
Run Code Online (Sandbox Code Playgroud)
我想使用SWRevealVC的委托.如果还有其他方式,请向我建议.
UIScreenEdgePanGestureRecognizer *panLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)];
[panLeft setEdges:UIRectEdgeLeft];
panLeft.minimumNumberOfTouches = 1;
panLeft.maximumNumberOfTouches = 1;
[self.view addGestureRecognizer:panLeft];
Run Code Online (Sandbox Code Playgroud)
委托SWRevealVC的方法
// The following methods provide a means to track the evolution of the gesture recognizer.
// The 'location' parameter is the X origin coordinate of the front view as the user drags it
// The 'progress' parameter is a positive value from 0 to 1 indicating the front …Run Code Online (Sandbox Code Playgroud) user-interface ios uiswipegesturerecognizer uipangesturerecognizer swrevealviewcontroller
我有一个包含计数器的视图.
我已经实现了两种不同的手势识别器,
UISwipeGesture将计数增加一,
和一个UIPanGesture,以便每次增加多个数字
用户刷卡的时间.
两种姿势都有效,但我的问题是它们不能同时工作.
我希望他们能够交替工作,例如,如果我做小滑动的话
计数器应该增加1,如果我继续向上拖动计数器
应该增加多个数字.
这是我的代码的一部分:
```
override func viewDidLoad() {
super.viewDidLoad()
setupSwipeGestures()
setupPanGestures()
}
private func setupSwipeGestures() {
let swipeUp = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let swipeDown = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
swipeUp.direction = .Up
swipeDown.direction = .Down
circleView.addGestureRecognizer(swipeUp)
circleView.addGestureRecognizer(swipeDown)
}
private func setupPanGestures() {
let panGesture = UIPanGestureRecognizer(target: self, action: Selector("handleThePan:"))
circleView.addGestureRecognizer(panGesture)
}
extension UIPanGestureRecognizer {
func isDown(circleView: UIView) -> Bool {
let velocity : CGPoint = velocityInView(circleView)
if velocity.y < 0 {
print("ex …Run Code Online (Sandbox Code Playgroud) uigesturerecognizer ios uiswipegesturerecognizer uipangesturerecognizer swift
所以我发现了如何使用 UIPanGestureRecognizer 使按钮可拖动。但我知道如何做到这一点的唯一方法是通过中心存储和拖动按钮。这样做的问题是,如果您尝试从角落拖动按钮,按钮会立即从角落移动到中心。我正在寻找一种解决方案,它可以让我的手指在移动时保持在选定的位置上,而不会立即锁定到中心。
我目前使用的代码:
func buttonDrag(pan: UIPanGestureRecognizer) {
print("Being Dragged")
if pan.state == .began {
print("panIF")
buttonCenter = button.center // store old button center
}else {
print("panELSE")
let location = pan.location(in: view) // get pan location
button.center = location // set button to where finger is
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
ios ×8
objective-c ×4
iphone ×2
cgpoint ×1
cocoa-touch ×1
distance ×1
drag ×1
gestures ×1
ipad ×1
swift ×1
swift3 ×1
uitableview ×1
xamarin.ios ×1
xcode ×1