我喜欢在UINavigationController中嵌入视图所继承的滑动包.不幸的是,我似乎找不到隐藏导航栏的方法,但仍然有触摸平移向后滑动手势.我可以编写自定义手势但我不喜欢和依赖UINavigationController后滑动手势.
如果我在故事板中取消选中它,则后滑动不起作用
或者如果我以编程方式隐藏它,相同的场景.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:NO]; // and animated:YES
}
Run Code Online (Sandbox Code Playgroud)
有没有办法隐藏顶部导航栏仍然有滑动?
xcode objective-c uinavigationcontroller uigesturerecognizer ios
我有一个UIPanGestureRecognizer
用来跟踪UIImageView
用户手指下方的对象().我只关心X轴上的运动,如果触摸偏离Y轴上物体框架的上方或下方,我想结束触摸.
我已经拥有了确定触摸是否在对象的Y边界内所需的一切,但我不知道如何取消触摸事件.翻转识别器的cancelsTouchesInView
属性似乎没有做我想要的.
谢谢!
好的,所以我一直在四处寻找太阳下用于捕捉多点触控手势的所有选项,我终于完成了一圈并回到了UIPanGestureRecognizer.
我想要的功能非常简单.我已经设置了一个双指平移手势,我希望能够根据我移动的像素数量来移动一些图像.我已经做得很好了,但我希望能够捕获平移手势是否已经反转.
有没有内置的方式,我只是没有看到回过头来做手势?我是否必须存储我的原始起点,然后跟踪终点,然后查看它们之后的移动位置,如果它小于初始终点,然后相应地反转?我可以看到工作,但我希望有一个更优雅的解决方案!
谢谢
编辑:
以下是识别器设置为触发的方法.它有点像黑客,但它有效:
-(void) throttle:(UIGestureRecognizer *) recognize{
throttleCounter ++;
if(throttleCounter == 6){
throttleCounter = 0;
[self nextPic:nil];
}
UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *) recognize;
UIView *view = recognize.view;
if(panGesture.state == UIGestureRecognizerStateBegan){
CGPoint translation = [panGesture translationInView:view.superview];
NSLog(@"X: %f, Y:%f", translation.x, translation.y);
}else if(panGesture.state == UIGestureRecognizerStateEnded){
CGPoint translation = [panGesture translationInView:view.superview];
NSLog(@"X: %f, Y:%f", translation.x, translation.y);
}
}
Run Code Online (Sandbox Code Playgroud)
我刚刚开始尝试跟踪值之间的差异......试着告诉他们正在淘汰的方式
我正在开发iphone(iOS 4.0或更高版本)应用程序,并且在多个视图之间处理触摸问题.我有这样的视图结构
---> A superView
|
---> SubView - A
|
---> SubView - B (exactly on top of A, completely blocking A).
Run Code Online (Sandbox Code Playgroud)
基本上我有一个superView和兄弟子视图A和B. B与A具有相同的框架,因此完全隐藏了A.
现在我的要求就是这个.
这就是我为视图添加手势识别器的方法
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe:)];
[leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
leftSwipe.delegate = self;
[bView addGestureRecognizer:leftSwipe];
[leftSwipe release];
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe:)];
[rightSwipe setDirection:(UISwipeGestureRecognizerDirectionRight)];
rightSwipe.delegate = self;
[bView addGestureRecognizer:rightSwipe];
[rightSwipe release];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
pinch.delegate = self;
[aView addGestureRecognizer:pinch];
[pinch release];
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,对我UIGestureRecognizerDelegate
看起来很有希望,我实现了委托方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer …
Run Code Online (Sandbox Code Playgroud) 我已经在申请了一段时间,但由于NDA,我无法提出这个问题.
我的Viewcontroller加载了UIPageViewController.视图控制器具有由PageViewControllers手势识别器覆盖的按钮.例如,我在viewcontroller的右侧有一个按钮,当你按下按钮时,PageViewController接管并更改页面.
如何让按钮接收触摸并取消PageViewController中的手势识别器?
我认为PageViewController使我的ViewController成为其视图的子视图.
我知道我可以关闭所有的手势,但这不是我正在寻找的效果.
我宁愿不子类PageViewController苹果表示,这个类是不是要被继承.
我是手势识别器的新手所以也许这个问题听起来很愚蠢:我正在为一堆UIViews分配轻拍手势识别器.在该方法中,有可能找出以某种方式点击它们中的哪一个,或者我是否需要使用点击屏幕上的点找到它?
for (NSUInteger i=0; i<42; i++) {
float xMultiplier=(i)%6;
float yMultiplier= (i)/6;
float xPos=xMultiplier*imageWidth;
float yPos=1+UA_TOP_WHITE+UA_TOP_BAR_HEIGHT+yMultiplier*imageHeight;
UIView *greyRect=[[UIView alloc]initWithFrame:CGRectMake(xPos, yPos, imageWidth, imageHeight)];
[greyRect setBackgroundColor:UA_NAV_CTRL_COLOR];
greyRect.layer.borderColor=[UA_NAV_BAR_COLOR CGColor];
greyRect.layer.borderWidth=1.0f;
greyRect.userInteractionEnabled=YES;
[greyGridArray addObject:greyRect];
[self.view addSubview:greyRect];
NSLog(@"greyGrid: %i: %@", i, greyRect);
//make them touchable
UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightLetter)];
letterTapRecognizer.numberOfTapsRequired = 1;
[greyRect addGestureRecognizer:letterTapRecognizer];
}
Run Code Online (Sandbox Code Playgroud) 我想从UIGestureRecognizer获取我的点击的UITouch位置,但我无法弄清楚如何查看文档和其他SO问题.你们其中一个可以指导我吗?
- (void)handleTap:(UITapGestureRecognizer *)tapRecognizer
{
CCLOG(@"Single tap");
UITouch *locationOfTap = tapRecognizer; //This doesn't work
CGPoint touchLocation = [_tileMap convertTouchToNodeSpace:locationOfTap];
//convertTouchToNodeSpace requires UITouch
[_cat moveToward:touchLocation];
}
Run Code Online (Sandbox Code Playgroud)
这里的固定代码 - 这也修复了Y轴
CGPoint touchLocation = [[CCDirector sharedDirector] convertToGL:[self convertToNodeSpace:[tapRecognizer locationInView:[[CCDirector sharedDirector] openGLView]]]];
Run Code Online (Sandbox Code Playgroud) 在UIImageView
我的子类初始化后,我有以下代码行:
self.userInteractionEnabled = true
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTap:"))
Run Code Online (Sandbox Code Playgroud)
我创建了必要的相关功能:
func handleTap(gestureRecognizer: UITapGestureRecognizer) {
print("In handler")
}
Run Code Online (Sandbox Code Playgroud)
在点击有问题的视图时,"处理程序从未打印到控制台".然后我删除了处理函数,看看编译器是否会抱怨丢失的函数.它没有.
我很难过.我真的很感激任何光明人都可以放弃这一点.
更新:我的课实际上是一个UIImageView
相反的UIView
我编写了Swift代码,试图从给定自定义UIView类型的所有子视图中删除所有手势识别器.
let mySubviews = self.subviews.filter() {
$0.isKindOfClass(CustomSubview)
}
for subview in mySubviews {
for recognizer in subview.gestureRecognizers {
subview.removeGestureRecognizer(recognizer)
}
}
Run Code Online (Sandbox Code Playgroud)
但该for recognizer
行会产生编译错误:
'[AnyObject]?' does not have a member named 'Generator'
Run Code Online (Sandbox Code Playgroud)
我已经尝试将for recognizer
循环更改为for recognizer in enumerate(subview.gestureRecognizers)
,但这会产生编译器错误:
Type '[AnyObject]?!' Does not conform to protocol 'SequenceType'
Run Code Online (Sandbox Code Playgroud)
我看到UIView的gestureRecognizers
方法返回了[AnyObject]??
,我认为双重包裹的返回值正在绊倒我.谁能帮我?
更新:修改,编译代码是:
if let recognizers = subview.gestureRecognizers {
for recognizer in recognizers! {
subview.removeGestureRecognizer(recognizer as UIGestureRecognizer)
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个视图,我在这个视图中应用了一个UIPanGestureRecogniser:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAnim:)];
[sliderView addGestureRecognizer:panGesture];
[panGesture release];
Run Code Online (Sandbox Code Playgroud)
我可以很好地检测和处理手势.但是,一旦手势结束,我希望启动另一种方法.
我知道有两种方法可以进行这种检测.touchesEnded
与touchesCancelled
然而,我发现,touchesCancelled
获取,一旦触摸成为一种姿态,即我将我的手指足以保证手势调用,并呼吁touchesEnded
很少,如果有的话,被调用.
我希望能够向左/向右平移,然后在手势结束时启动另一个函数调用.我该怎么做呢?