1:手势:
//单击
UITapGestureRecognizer * tapGestuer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction)];
tapGestuer.delegate =self;
[self.view addGestureRecognizer:tapGestuer];
//左轻扫手势
UISwipeGestureRecognizer * leftSwipeGesture =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeGestureAction)];
leftSwipeGesture.delegate = self;
leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwipeGesture];
//右轻扫手势
UISwipeGestureRecognizer * rightSwipeGuesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeGuestAction)];
rightSwipeGuesture.delegate = self;
rightSwipeGuesture.direction =UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipeGuesture];
2:point 是否在一个标准范围内
/* Return true if `point' is contained in `rect', false otherwise. */
CG_EXTERN bool CGRectContainsPoint(CGRect rect, CGPoint point)
CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
- (void)tapAction:(UITapGestureRecognizer *)tap{
CGPoint point = [tap locationInView:self.view];
// BOOL isTapMiddle = CGRectContainsPoint(CGRectMake(self.view.frame.size.width/2 -50, self.view.frame.size.height/2 -50, 100, 100), point);
BOOL isTapMiddle = CGRectContainsPoint(CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 160), point);
if (isTapMiddle) {
self.pageMenuView.hidden = !self.pageMenuView.hidden;
}
}
3: 将html文字显示到uitextView里
NSString * contentStr = [NSString stringWithFormat:@"%@
%@
%@
%@%@
",BgTitle,fangContent,strFan1,tanslationStr,gist];
NSAttributedString * attributedString = [[NSAttributedString alloc]initWithData:[contentStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{
NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSFontAttributeName: [BookManager sharedInstance].contentFont
} documentAttributes:nil error:nil];
self.contentAll = contentStr;
self.textView.attributedText =attributedString;
4: block回掉,异步执行回到主线程,fmdb数据库
.h文件
声明block:
typedef void(^CompleteBlock)(NSMutableArray * dataArray, NSError *error);
.m文件
+ (instancetype)sharedQueue{
static VFMDataManager * manager = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
manager = [[VFMDataManager alloc] initWithQueue];
});
return manager;
}
- (instancetype)initWithQueue{
self = [super init];
if (self) {
[self createDatabaseQueue];
}
return self;
}
- (void )dxbookSectionWithBookID:(NSString *)bookID
completionBlock:(CompleteBlock)block{
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_dataBaseQueue inDatabase:^(FMDatabase *db) {
NSMutableArray *array = [[NSMutableArray alloc]init];
NSString *sql = @"select chapter_id,chapter_zh_name,sj from chapter_akdx orderby where book_id = ?";
FMResultSet *result=[db executeQuery:sql,bookID];
while ([result next]) {
NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
[dic setValue:[result stringForColumn:@"chapter_id"] forKey:@"chapter_id"];
[dic setValue:[result stringForColumn:@"chapter_zh_name"] forKey:@"chapter_zh_name"];
[dic setValue:[result stringForColumn:@"sj"] forKey:@"sj"];
[array addObject:dic];
}
dispatch_async(dispatch_get_main_queue(), ^{
block(array,nil);
[SVProgressHUD dismiss];
});
}];
});
}
- (void)createDatabaseQueue{
NSString * documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
NSLog(@"-----%@",filePath);
if(![fileManager fileExistsAtPath:filePath]) //如果不存在
{
NSLog(@"vedabooks.db is not exist");
NSString *dataPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/vedabooks.db"];//获取程序包中相应文件的路径
NSError *error;
if([fileManager copyItemAtPath:dataPath toPath:filePath error:&error]) //拷贝
{
NSLog(@"copy vedabooks.db success");
}
else
{
NSLog(@"%@",error);
}
}
_dataBaseQueue = [[FMDatabaseQueue alloc]initWithPath:filePath];
}
//获取document目录并返回数据库目录
- (NSString *)dataFilePath
{
//方法1
// NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
NSString * path = [documentsDirectory stringByAppendingPathComponent:@"vedabooks.db"];
// NSLog(@"iapChinaPurchase-->%@",path);
return path;
}
5:联合查询:from sections2 a,:---》将sections2映射为表a
NSString *sqlbook1 = [NSString stringWithFormat:@"select a.*,b.book_zh_name,b.book_en_name,c.chapter_zh_name,c.chapter_en_name from sections2 a,vd_books b,chapter c where a.book_id=b.book_id and a.chapter_id=c.chapter_id and a.book_id=1 and (a.yw_zh2 like '%%%@%%' or a.yw_en2 like '%%%@%%') order by a.book_id, a.chapter_id,(a.section_id+0)",text,text];
FMResultSet *result=[db executeQuery:sqlbook1];
while ([result next]) {
NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
[dic setValue:[result stringForColumn:@"book_zh_name"] forKey:@"book_zh_name"];
[array addObject:dic];
}
6:设置指定位置文字的颜色
NSString * textStr =@"项目管理师是指掌握项目管理原理、技术、方法和工具,参与或领导启动、计划、组织、执行、控制和收尾过程的活动,确保项目能在规定的范围、时间、质量与成本等约束条件下完成既定目标的人员。";
NSString * tagStr = @"项目";
NSMutableAttributedString * detial = [[NSMutableAttributedString alloc] initWithString:textStr
];
[detial addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[textStr rangeOfString:tagStr]];// 关键步骤,设置指定位置文字的颜色
self.labels.lineBreakMode = NSLineBreakByWordWrapping;
self.labels.numberOfLines = 0;
self.labels.attributedText = detial;