如題
上代碼
#pragma mark ------ - 創(chuàng)建 tableview的headview ----
- (UIView *)creadTableViewHeadView{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger selectedBook = [defaults integerForKey:@"selectedBook"];//讀取當前閱讀書籍
//創(chuàng)建 tableview的headview 展示當前閱讀的書 以及進度
UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH, screen_height/3-20)];
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH/2-60, screen_height/3-60)];
[imageView sd_setImageWithURL:[NSURL URLWithString:_dataArray[1][selectedBook]]];
///////////////***沖突*************////////
// headView 模糊背景效果
// UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
//
// UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect];
//
// view.frame = headView.bounds;
//
//
// headView.backgroundColor = [UIColor colorWithPatternImage:imageView.image];
// [headView addSubview:view];
//
更改后的代碼 調(diào)用以下方法
//生成一張毛玻璃圖片 將圖片設為背景顏色
/*
- (UIImage*)blur:(UIImage*)theImage
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
UIImage *returnImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return returnImage;
}
*/
UILabel * headViewLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-20, 40, 140, 30)];
headViewLabel.text = _dataArray[0][selectedBook];
//閱讀進度 label
UILabel * progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+60, (screen_height/3-20)/2, 100, 30)];
float bookReadingProgress = [defaults floatForKey:[NSString stringWithFormat:@"bookReadingProgress%ld",[_dataArray[2][selectedBook] integerValue]]];//讀取當前閱讀書籍進度
progressLabel.text = [[NSString stringWithFormat:@"%.2f",bookReadingProgress*100] stringByAppendingString:@"%"];
//進度條在左 詳細進度百分比在右
UIProgressView * progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.frame = CGRectMake(SCREEN_WIDTH/2-20, (screen_height/3-20)/2+10, 40, 10);
progressView.progress = bookReadingProgress;
[headView addSubview:progressView];
//繼續(xù)閱讀按鈕
UIButton * continueReadingButton = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-100 , screen_height/3-60, 80, 40)];
[continueReadingButton setTitle:@"繼續(xù)閱讀" forState:UIControlStateNormal];
[continueReadingButton addTarget:self action:@selector(continueReading) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:continueReadingButton];
[headView addSubview:progressLabel];
[headView addSubview:headViewLabel];
[headView addSubview:imageView];
//封面旋轉(zhuǎn)效果
CATransform3D transform = CATransform3DIdentity;
//apply perspective
transform.m34 = - 1.0 / 500.0;
//rotate by 45 degrees along the Y axis
transform = CATransform3DRotate(transform, -M_PI/6,0, 1, 0);
//apply to layer
imageView.layer.transform = transform;
//
return headView;
}