麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

仿面包旅行個人中心下拉頂部背景放大高斯模糊效果

2019-11-14 18:52:00
字體:
來源:轉載
供稿:網友

HeaderView.h

////  HeaderView.h//  仿面包旅行個人中心////  Created by [email protected] on 15/5/14.//  Copyright (c) 2015年 wb145230. All rights reserved.//#import <UIKit/UIKit.h>@interface HeaderView : UIView@PRoperty(nonatomic, strong) UIScrollView *imageScrollView;@property(nonatomic, strong) UIImageView *imageView;                //背景圖片@property(nonatomic, strong) UIImageView *imageBackgroundView;      //要改變的背景圖片/** *  改變頂部view的大小和高斯效果 * *  @param offset scrollview滑動的記錄 */-(void)updateHeaderView:(CGPoint) offset;@end

 

HeaderView.m

////  HeaderView.m//  仿面包旅行個人中心////  Created by [email protected] on 15/5/14.//  Copyright (c) 2015年 wb145230. All rights reserved.//#import "HeaderView.h"#import <Accelerate/Accelerate.h>@implementation HeaderView- (instancetype)initWithFrame:(CGRect)frame {    if (self = [super initWithFrame:frame]) {        self.imageScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];        [self addSubview:self.imageScrollView];                UIImage *image = [UIImage imageNamed:@"header_bg"];        //高斯的背景圖片        self.imageBackgroundView = [[UIImageView alloc] initWithFrame:self.imageScrollView.bounds];        [self setBlurryImage:image];        self.imageBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;        self.imageBackgroundView.contentMode = UIViewContentModeScaleaspectFill;        [self.imageScrollView addSubview:self.imageBackgroundView];                //原圖        self.imageView = [[UIImageView alloc] initWithFrame:self.imageScrollView.bounds];        self.imageView.image = image;        self.imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;        self.imageView.contentMode = UIViewContentModeScaleAspectFill;        [self.imageScrollView addSubview:self.imageView];    }        return self;}/** *  通過scrollview的滑動改變頂部view的大小和高斯效果 * *  @param offset scrollview下滑的距離 */-(void)updateHeaderView:(CGPoint) offset {    if (offset.y < 0) {        CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);        CGFloat delta = fabs(MIN(0.0f, offset.y));        rect.origin.y -= delta;        rect.size.height += delta;        self.imageScrollView.frame = rect;        self.clipsToBounds = NO;                self.imageView.alpha = fabs(offset.y / (2 * CGRectGetHeight(self.bounds) / 3));    }}/** *  高斯圖片 * *  @param originalImage 需要高斯的圖片 */- (void)setBlurryImage:(UIImage *)originalImage {        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{        UIImage *blurredImage = [self blurryImage:originalImage withBlurLevel:0.9];                dispatch_async(dispatch_get_main_queue(), ^{            self.imageView.alpha = 0.0;            self.imageBackgroundView.image = blurredImage;        });    });    }/** *  高斯背景 * *  @param image    需要高斯模糊的圖片 *  @param blur     高斯模糊的值 * *  @return */- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {    if ((blur < 0.0f) || (blur > 1.0f)) {        blur = 0.5f;    }        int boxSize = (int)(blur * 100);    boxSize -= (boxSize % 2) + 1;        CGImageRef img = image.CGImage;        vImage_Buffer inBuffer, outBuffer;    vImage_Error error;    void *pixelBuffer;        CGDataProviderRef inProvider = CGImageGetDataProvider(img);    CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);        inBuffer.width = CGImageGetWidth(img);    inBuffer.height = CGImageGetHeight(img);    inBuffer.rowBytes = CGImageGetBytesPerRow(img);    inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);        pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));        outBuffer.data = pixelBuffer;    outBuffer.width = CGImageGetWidth(img);    outBuffer.height = CGImageGetHeight(img);    outBuffer.rowBytes = CGImageGetBytesPerRow(img);        error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);            if (error) {        NSLog(@"error from convolution %ld", error);    }        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();    CGContextRef ctx = CGBitmapContextCreate(outBuffer.data, outBuffer.width, outBuffer.height, 8, outBuffer.rowBytes, colorSpace, CGImageGetBitmapInfo(image.CGImage));        CGImageRef imageRef = CGBitmapContextCreateImage (ctx);    UIImage *returnImage = [UIImage imageWithCGImage:imageRef];        //clean up    CGContextRelease(ctx);    CGColorSpaceRelease(colorSpace);        free(pixelBuffer);    CFRelease(inBitmapData);        CGColorSpaceRelease(colorSpace);    CGImageRelease(imageRef);        return returnImage;}@end

 

ViewController.h

////  ViewController.h//  仿面包旅行個人中心////  Created by [email protected] on 15/5/14.//  Copyright (c) 2015年 wb145230. All rights reserved.//#import <UIKit/UIKit.h>#import "HeaderView.h"@interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>@property(nonatomic, strong) UITableView *tableView;@property(nonatomic, strong) HeaderView *headerView;@end

 

ViewController.m

////  ViewController.m//  仿面包旅行個人中心////  Created by [email protected] on 15/5/14.//  Copyright (c) 2015年 wb145230. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [[UIapplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];        self.view.backgroundColor = [UIColor whiteColor];        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];    self.tableView.dataSource = self;    self.tableView.delegate = self;    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;    self.tableView.separatorColor = [UIColor clearColor];    self.tableView.showsVerticalScrollIndicator = NO;        self.headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 250)];    self.tableView.tableHeaderView = self.headerView;    [self.view addSubview:self.tableView];    }-(void)scrollViewDidScroll:(UIScrollView *)scrollView {    [self.headerView updateHeaderView:scrollView.contentOffset];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return 10;}- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];    if (cell == nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];    }    cell.selectionStyle = UITableViewCellSelectionStyleNone;    return cell;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}@end

 

效果

 

如果你不是在wb145230博客園看到本文,請點擊查看原文.

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高潮激情aaaaa免费看 | 国产日本在线播放 | 国产精品国产三级国产在线观看 | 午夜影视一区二区 | 黑人一区二区三区四区五区 | 久久综合婷婷 | 亚洲综合精品 | 久久经典国产视频 | 99在线免费观看视频 | 久久96国产精品久久秘臀 | 91九色视频观看 | 亚洲影院在线播放 | 国产精品久久久久久久久久久久久久久久 | 黄色av网站免费看 | 欧美18—19sex性护士中国 | 成人毛片网 | 国产成人自拍小视频 | 亚洲婷婷日日综合婷婷噜噜噜 | 天天草天天干天天 | 最近国产中文字幕 | 成人午夜免费看 | 久久国产精品小视频 | 久久精品美乳 | 黄色片免费在线 | 欧美性生活区 | 国产免费成人 | 国产88久久久国产精品免费二区 | 精品乱码久久久久 | 久草免费新视频 | 操操操日日日干干干 | 亚洲国产成人久久成人52 | 免费观看一级黄色片 | 日韩毛片一区二区三区 | 国产一精品一av一免费爽爽 | 亚州欧美视频 | 国产在线免费 | lutube成人福利在线观看 | 色婷婷久久一区二区 | 亚洲午夜一区二区三区 | 成人在线视频国产 | 国色天香综合网 |