小知识点

tableView的分割线设置为全行的方法

- (void)viewDidLayoutSubviews

{

[super viewDidLayoutSubviews];

if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {

[_tableView setSeparatorInset:UIEdgeInsetsZero];

}

}

1.如何讲一个view保存为PDF格式

-(void)createPDFfromUIView:(UIView *)aView saveToDocumentsWithFileName:(NSString *)afileName{

NSMutableData *pdfData = [NSMutableData data];

UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);

UIGraphicsBeginPDFPage();

CGContextRef pdfContext = UIGraphicsGetCurrentContext();

[aView.layer renderInContext:pdfContext];

UIGraphicsEndPDFContext();

NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentDirectory = [documentDirectories objectAtIndex:0];

NSString *documentDirectoryFileName = [documentDirectory stringByAppendingPathComponent:afileName];

[pdfData writeToFile:documentDirectoryFileName atomically:YES];

}

2.UIWebView添加单击手势不响应

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(webviewClick)];

tap.delegate = self;

[_webView addGestureRecognizer:tap];

因为webview本身有一个单击手势,所以在添加会造成手势冲突,从而不响应,需要绑定手势代理,并实现下面的代理方法

.允许多个手势识别器共同识别

默认情况下,两个gesture recognizers不会同时识别它们的手势,但是你可以实现UIGestureRecognizerDelegate协议中的

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:方法对其进行控制。这个方法在这两个gesture recognizers中的任意一个将block另一个的触摸事件时调用,如果返回YES,则两个gesture recognizers可同时识别,如果返回NO,则并不保证两个gesture recognizers必不能同时识别,因为另外一个gesture recognizer的此方法可能返回YES。也就是说两个gesture recognizers的delegate方法只要任意一个返回YES,则这两个就可以同时识别;只有两个都返回NO的时候,才是互斥的。默认情况下是返回NO。

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer{

return YES;

}

3.隐藏UITextView/UITextField光标

textField.tintColor = [UIColor clearColor];

4.当UITextView/UITextField中没有文字的时候,禁用回车键

textField.enablesReturnKeyAutomatically = YES;

5.单个页面多个网络请求的情况,需要监听所有网络请求结束后刷新UI

dispatch_group_t group = dispatch_group_create();

dispatch_queue_t serialQueue = dispatch_queue_create("com.wzb.test.www", DISPATCH_QUEUE_SERIAL);

dispatch_group_enter(group);

dispatch_group_async(group, serialQueue, ^{

// 网络请求一

[WebClick getDataSuccess:^(ResponseModel *model) {

dispatch_group_leave(group);

} failure:^(NSString *err) {

dispatch_group_leave(group);

}];

});

dispatch_group_enter(group);

dispatch_group_async(group, serialQueue, ^{

// 网络请求二

[WebClick getDataSuccess:getBigTypeRM onSuccess:^(ResponseModel *model) {

dispatch_group_leave(group);

}                                  failure:^(NSString *errorString) {

dispatch_group_leave(group);

}];

});

dispatch_group_enter(group);

dispatch_group_async(group, serialQueue, ^{

// 网络请求三

[WebClick getDataSuccess:^{

dispatch_group_leave(group);

} failure:^(NSString *errorString) {

dispatch_group_leave(group);

}];

});

// 所有网络请求结束后会来到这个方法

dispatch_group_notify(group, serialQueue, ^{

dispatch_async(dispatch_get_global_queue(0, 0), ^{

dispatch_async(dispatch_get_main_queue(), ^{

// 刷新UI

});

});

});

6.IOS中截屏的方法

- (UIImage *)captureScrollView:(UIScrollView *)scrollView{

UIImage* image = nil;

UIGraphicsBeginImageContext(scrollView.contentSize);

{

CGPoint savedContentOffset = scrollView.contentOffset;

CGRect savedFrame = scrollView.frame;

scrollView.contentOffset = CGPointZero;

scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);

[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];

image = UIGraphicsGetImageFromCurrentImageContext();

scrollView.contentOffset = savedContentOffset;

scrollView.frame = savedFrame;

}

UIGraphicsEndImageContext();

if (image != nil) {

return image;

}

return nil;

}

你可能感兴趣的:(小知识点)