Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIgestureRecognitzerDelegate实现不';行不通_Ios_Objective C_Xcode_Ios8 - Fatal编程技术网

Ios UIgestureRecognitzerDelegate实现不';行不通

Ios UIgestureRecognitzerDelegate实现不';行不通,ios,objective-c,xcode,ios8,Ios,Objective C,Xcode,Ios8,我尝试在我的ViewController中实现UIgestureRecognitzerDelegate,但不知何故,这些方法没有被调用。这是控制器: #import "DiaryEntryViewController.h" #import "UINavigationController+BarManagement.h" @interface DiaryEntryViewController ()<UIGestureRecognizerDelegate> @property (str

我尝试在我的ViewController中实现UIgestureRecognitzerDelegate,但不知何故,这些方法没有被调用。这是控制器:

#import "DiaryEntryViewController.h"
#import "UINavigationController+BarManagement.h"

@interface DiaryEntryViewController ()<UIGestureRecognizerDelegate>
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation DiaryEntryViewController

-(void)viewWillAppear:(BOOL)inAnimated{
    [super viewWillAppear:inAnimated];
    self.navigationController.barsHidden = NO;
}

-(void)viewDidAppear:(BOOL)inAnimated{
    [super viewDidAppear:inAnimated];
    [self.navigationController hideBarsWithDelay:2.0];
}

-(void)viewWillDisappear:(BOOL)inAnimated{
    [self.navigationController setBarsHidden:NO animated:YES];
    [super viewWillDisappear:inAnimated];
}

-(NSManagedObjectContext *)managedObjectContext{
    return self.diaryEntry.managedObjectContext;
}

-(BOOL)saveDiaryEntry{
    BOOL theResult = NO;
    NSError *theError = nil;

    theResult = [self.managedObjectContext save:&theError];
    if(!theResult){
        NSLog(@"saveItem %@", theError);
    }

    return theResult;
}

-(CGRect)visibleBounds{
    CGRect theBounds = self.view.bounds;

    if([self respondsToSelector:@selector(topLayoutGuide)] && [self respondsToSelector:@selector(bottomLayoutGuide)]){
        theBounds.origin.y = [self.topLayoutGuide length];
        theBounds.size.height -= [self.topLayoutGuide length] + [self.bottomLayoutGuide length];
    }
    return theBounds;
}

-(IBAction)toogleBars:(id)sender{
    NSLog(@"toogleBars");
    UINavigationController *theController = self.navigationController;
    BOOL theHiddenFlag = theController.barsHidden;

    [theController setBarsHidden:!theHiddenFlag animated:YES];
    if(theHiddenFlag){
        [theController hideBarsWithDelay:2.0];
    }

}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)inRecognizer{
    NSLog(@"gestureRecognizerShouldBegin");
    UIView *theView = self.textView;
    CGPoint thePoint = [inRecognizer locationInView:theView];

    return !CGRectContainsPoint(theView.bounds, thePoint);
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    NSLog(@"bla");

    return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    NSLog(@"ble");
    return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    NSLog(@"blä");
    return YES;
}

@end
#导入“DiaryEntryViewController.h”
#导入“UINavigationController+BarManagement.h”
@接口DiaryEntryViewController()
@属性(强,非原子)NSManagedObjectContext*managedObjectContext;
@属性(弱、非原子)IBOutlet UITextView*textView;
@结束
@实现DiaryEntryViewController
-(void)视图将出现:(BOOL)无生命{
[超级视图将显示:无生命];
self.navigationController.barsHidden=否;
}
-(void)视图显示:(BOOL)无生命{
[超级视图显示:无生命];
[self.navigationController Hidebars with Delay:2.0];
}
-(void)视图将消失:(BOOL)无生命{
[self.navigationController setBarsHidden:否动画:是];
[超级视图将消失:无生命];
}
-(NSManagedObjectContext*)managedObjectContext{
返回self.diaryEntry.managedObjectContext;
}
-(BOOL)saveDiaryEntry{
BOOL-theResult=否;
n错误*错误=零;
结果=[self.managedObjectContext保存:&错误];
如果(!theResult){
NSLog(@“saveItem%@”,错误);
}
返回结果;
}
-(CGRect)可见边界{
CGRect theBounds=self.view.bounds;
if([self-respondsToSelector:@selector(topLayoutGuide)]&&[self-respondsToSelector:@selector(topLayoutGuide)]){
theBounds.origin.y=[self.topLayoutGuide-length];
bounds.size.height-=[self.topLayoutGuide length]+[self.bottomLayoutGuide length];
}
返回边界;
}
-(iAction)toogleBars:(id)发送方{
NSLog(@“Toogebars”);
UINavigationController*控制器=self.navigationController;
BOOL theHiddenFlag=控制器.barsHidden;
[控制器设置隐藏:!隐藏标志已设置动画:是];
如果(隐藏标志){
[控制器隐藏延迟:2.0];
}
}
-(BOOL)手势识别器应在识别器中开始:(UIGestureRecognizer*){
NSLog(@“手势识别器应开始”);
UIView*theView=self.textView;
CGPoint thePoint=[在识别器位置视图中:视图];
return!CGRectContainsPoint(theView.bounds,thePoint);
}
-(BOOL)手势识别器:(UIGestureRecognizer*)手势识别器应不需要AI手势识别器:(UIGestureRecognizer*)其他手势识别器{
NSLog(@“bla”);
返回YES;
}
-(BOOL)GestureRecognitor:(UIGestureRecognitor*)GestureRecognitor应要求GestureRecognitor:(UIGestureRecognitor*)其他GestureRecognitor{
NSLog(@“ble”);
返回YES;
}
-(BOOL)手势识别器:(UIGestureRecognizer*)手势识别器应与gestureRecognizer:(UIGestureRecognizer*)其他手势识别器同时识别{
NSLog(“blä”);
返回YES;
}
@结束

它确实调用toogleBars方法,但不调用任何识别器方法。

不要忘记声明识别器,并将其添加到要检测轻触或滑动的视图中

例如:

在VC中添加一个属性,如“theTapRecognizer”

Alloc和init识别器:

self.theTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(someMethod:)];
self.theTapRecognizer.delegate = self;
[someView addGestureRecognizer: selftheTapRecognizer];
someView是要初始化识别器的视图的占位符文本,它可以是整个self.view或某个子视图, 您可以使用以下委托方法监听与该手势识别器的任何交互

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

假设您已从情节提要中添加了
UIGestureRecognitor
,则需要记住CTRL+Drag将手势对象拖动到
UIViewController
黄色圆圈图像并设置代理

您的
UIGestureRecognitor
对象将位于
UIViewController
视图的顶部。CTL将其拖动到黄色圆圈ViewController图标

然后,此弹出窗口将显示并选择“委托”,以便GeSutureRecognitor将使用委托方法


您尚未声明任何UIgestureRecognitor实例,仅添加代理还不够我认为您是通过情节提要直接添加UIgestureRecognitor的?