我想在基于视图的iPhone项目中添加简单的滑动手势识别功能.应识别所有方向(右,下,左,上)的手势.
它在UISwipeGestureRecognizer的文档中说明:
您可以通过使用按位或操作数指定多个UISwipeGestureRecognizerDirection常量来指定多个方向.默认方向是UISwipeGestureRecognizerDirectionRight.
但对我来说它不起作用.当所有四个方向都被"或"时,仅识别左右滑动.
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
}
Run Code Online (Sandbox Code Playgroud)
我通过在视图中添加四个识别器来修复此问题,但我很想知道它为什么不像在文档中宣传的那样工作?
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer]; …Run Code Online (Sandbox Code Playgroud) 我需要使用滑动来识别向下然后向右滑动手势.但是在快速的UISwipeGestureRecognizer上预先确定了正确的方向..而且我不知道如何使用其他方向.
我有一个UIViewController实现TableViews委托和数据源协议.现在我想向细胞添加"轻扫删除"手势.
我应该怎么做呢.
我给出了commitEditingStyle方法的空白实现,并将Editing属性设置为YES.
仍然没有滑动功能.
现在我需要单独添加UISwipeGesture到每个单元格吗?
或者我错过了什么?
我需要识别所有方向的滑动(向上/向下/向左/向右).不是同时,但我需要认识到它们.
我试过了:
UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeRecognizer:)];
Swipe.direction = (UISwipeGestureRecognizerDirectionLeft |
UISwipeGestureRecognizerDirectionRight |
UISwipeGestureRecognizerDirectionDown |
UISwipeGestureRecognizerDirectionUp);
[self.view addGestureRecognizer:Swipe];
[Swipe release];
Run Code Online (Sandbox Code Playgroud)
但没有出现 SwipeRecognizer
这是SwipeRecognizer的代码:
- (void) SwipeRecognizer:(UISwipeGestureRecognizer *)sender {
if ( sender.direction == UISwipeGestureRecognizerDirectionLeft )
NSLog(@" *** SWIPE LEFT ***");
if ( sender.direction == UISwipeGestureRecognizerDirectionRight )
NSLog(@" *** SWIPE RIGHT ***");
if ( sender.direction == UISwipeGestureRecognizerDirectionDown )
NSLog(@" *** SWIPE DOWN ***");
if ( sender.direction == UISwipeGestureRecognizerDirectionUp )
NSLog(@" *** SWIPE UP ***");
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?如何为我的滑动对象分配所有不同的方向?
iphone objective-c ipad uigesturerecognizer uiswipegesturerecognizer
我需要检测我的滑动手势的方向,我有问题.手势正在工作,但我不知道如何检测方向....
swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)];
[swipeGesture setNumberOfTouchesRequired:1];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp];
[appView addGestureRecognizer:swipeGesture];
-(void)detectSwipe:(UISwipeGestureRecognizer *)recognizer {
switch (recognizer.direction) {
case UISwipeGestureRecognizerDirectionUp:
NSLog(@"smth1");
break;
case UISwipeGestureRecognizerDirectionDown:
NSLog(@"smth2");
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用:/
objective-c gesture-recognition swipe ios uiswipegesturerecognizer
我SwipeRefreshLayout在下面的布局中使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/homePageBackground"
android:orientation="vertical" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout_listView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<fragment
android:id="@+id/announcementHomefragment"
android:name="in.test.app.AnnouncementFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/homePageBackground" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="@color/homePageBackground" >
<TextView
android:id="@+id/newsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/new_list"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/newshomefragment"
android:name="in.test.app.NewsFragment"
android:layout_width="wrap_content"
android:layout_height="190dp"
android:layout_below="@id/newsTitle"
android:layout_marginTop="-15dp" />
<TextView
android:id="@+id/productTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/newshomefragment"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/product_in_home"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/proCategoryhomefragment"
android:name="in.test.app.CategoryFragment"
android:layout_width="wrap_content"
android:layout_height="170dp" …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments uiswipegesturerecognizer swiperefreshlayout
我添加了这段代码 cellForRowAtIndexPath
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeFrom:)];
[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:gestureR];
Run Code Online (Sandbox Code Playgroud)
它工作正常.但我想要UISwipeGestureRecognizerDirectionLeft这样添加
[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];
Run Code Online (Sandbox Code Playgroud)
当我检查方向和状态时,我总是得到3 = 3
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"%d = %d",recognizer.direction,recognizer.state);
}
Run Code Online (Sandbox Code Playgroud)
如果我只申请一个手势,它可以正常工作.我试着逐个添加两个手势.但它只会响应一个手势.
如何添加第二个手势.我直接添加到一个手势到TableView另一个到单元格,但现在使用.
iphone objective-c ios5 uiswipegesturerecognizer swipe-gesture
我正在开发一个应用程序,我使用了Pan Gesture以及Swipe Gesture.因此,每次我执行Swipe Gesture时,Pan手势中的方法总是被调用,并且Swipe Gesture方法不会被调用.
所有的手势方法之间有没有优先权?
iphone uigesturerecognizer ios uiswipegesturerecognizer uipangesturerecognizer
我已经添加了一个UISwipeGestureRecognizer到我的Xcode笔尖,并在那里使我的应用程序崩溃:
..exception'NSInvalidArgumentException',原因:' - [UISwipeGestureRecognizer initWithCoder:]:无法识别的选择器发送到实例0x5c2ab30'.
为什么?
好的,这就是我遇到的问题:
我试图从viewController我命名的MenuViewController包含我的菜单的那个(显然)切换.我有一个单独的viewController名字ViewController,包含我的mapView.我希望能够增加一倍手指swipe left从我MenuViewController到我mapView.
我不确定从哪里开始.
另外,我使用的是xib文件,而不是故事板.运行iOS 6.
ios ×7
iphone ×4
objective-c ×4
swipe ×3
android ×1
cocoa-touch ×1
direction ×1
ios5 ×1
ipad ×1
swift ×1
uikit ×1
uitableview ×1