代码笔记,模糊视图

来源:http://www.smjxgs.com 作者:操作系统 人气:80 发布时间:2019-08-08
摘要:【代码笔记】iOS-UIAlertView3秒后消失, 4887王中王鉄算盘奖结果,一,效果图。 二,代码。 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIAle

【代码笔记】iOS-UIAlertView3秒后消失,

4887王中王鉄算盘奖结果,一,效果图。

4887王中王鉄算盘奖结果 1

二,代码。

4887王中王鉄算盘奖结果 2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:nil message:@"此信息3秒后消失" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];

    [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:3.0];
}
- (void)dismissAlert:(UIAlertView*)alert {
    if ( alert.visible ) {
        [alert dismissWithClickedButtonIndex:alert.cancelButtonIndex animated:YES];
    }
}

一,效果图。 二,代码。 - ( void )viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view,...

为了让界面更加美观,有时候我们需要将图片设置成模糊,比如下边这张图片:

【代码笔记】正在加载,代码笔记

一,效果图。

4887王中王鉄算盘奖结果 3

二,代码。

4887王中王鉄算盘奖结果 4

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    [self showFooter:YES];
}
-(void)showFooter:(BOOL)showFooter
{
    NSLog(@"上拉刷新:加载更多view");

    if(!loadMoreView)
    {
        loadMoreView=[[UIView alloc]init];

        //加载控件
        UIActivityIndicatorView *activeView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

        [activeView setFrame:CGRectMake(110, 10, 30, 30)];
        [activeView setBackgroundColor:[UIColor clearColor]];
        [loadMoreView addSubview:activeView];
        [activeView startAnimating];


        //文本
        UILabel *loadLabel=[[UILabel alloc]initWithFrame:CGRectMake(140, 10, 150, 30)];
        [loadLabel setTextAlignment:NSTextAlignmentLeft];
        [loadLabel setText:@"正在加载"];
        [loadLabel setTextColor:[UIColor colorWithRed:150/255.00 green:150/255.00 blue:150/255.00 alpha:1.0]];
        [loadLabel setBackgroundColor:[UIColor clearColor]];
        [loadMoreView addSubview:loadLabel];
    }

    [loadMoreView setFrame:CGRectMake(0, 60, 320, 100)];
    [loadMoreView setBackgroundColor:[UIColor clearColor]];

    if(!loadMoreView.superview)
    {
        [self.view addSubview:loadMoreView];
    }
    if(showFooter)
    {
       [loadMoreView setAlpha:1];
    }
    else
    {
       [loadMoreView setAlpha:0];
    }

}

一,效果图。 二,代码。 - (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. [self...

4887王中王鉄算盘奖结果 5CoreImage/CoreImage初窥

这篇文章主要演示了三种模糊效果,如下:

  • 原图

    4887王中王鉄算盘奖结果 6原图

  • 毛玻璃效果

    4887王中王鉄算盘奖结果 7毛玻璃效果

  • 代码如下:

#import "ViewController.h"#import <CoreImage/CoreImage.h>@interface ViewController ()@property (nonatomic, strong) UIImageView *imageView;@end@implementation ViewController- viewDidLoad { [super viewDidLoad]; self.imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; self.imageView.image = [UIImage imageNamed:@"1.jpg"]; self.imageView.contentMode = UIViewContentModeScaleAspectFill; [self.view addSubview:self.imageView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, self.view.frame.size.height - 80, self.view.frame.size.width, 40); [button setTitle:@"蒙奇·D·路飞" forState:UIControlStateNormal]; button.backgroundColor = [UIColor brownColor]; [button addTarget:self action:@selector("点击调用的方法") forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];}

button 被点击时调用以下代码:

 self.imageView = [[UIImageView alloc] initWithFrame:self.view.frame]; self.imageView.image = [UIImage imageNamed:@"1.jpg"]; UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blur]; visualEffectView.frame = self.view.frame; [self.imageView addSubview:visualEffectView]; UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blur]; UIVisualEffectView *ano = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect]; ano.frame = self.view.frame; UILabel *label = [[UILabel alloc] init]; label.font = [UIFont systemFontOfSize:40]; label.frame = CGRectMake(0, self.view.frame.size.height - 120, self.view.frame.size.width, 80); label.textAlignment = NSTextAlignmentCenter; label.text = @"蒙奇·D·路飞"; [visualEffectView.contentView addSubview:ano]; [ano.contentView addSubview:label]; [self.view addSubview:self.imageView];
  • 原图

4887王中王鉄算盘奖结果 8原图

  • 运动模糊效果图

    4887王中王鉄算盘奖结果 9运动模糊

  • 代码如下

viewDidLoad 中的代码和“简单的毛玻璃效果”中的 viewDidLoad 是一样的,这里只简单贴出 button 被点击调用的代码

 CIImage *inputImage = [CIImage imageWithCGImage:self.imageView.image.CGImage]; // CIGaussianBlur 高斯模糊 // CIBoxBlur 均值模糊 // CIDiscBlur 环形卷积模糊 // CIMotionBlur 运动模糊 CIFilter *filter = [CIFilter filterWithName:@"CIMotionBlur"]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:@5 forKey:kCIInputRadiusKey]; CIContext *context = [CIContext contextWithOptions:nil]; CIImage *outupImage = filter.outputImage; CGImageRef imageRef = [context createCGImage:outupImage fromRect:outupImage.extent]; self.imageView.image= [UIImage imageWithCGImage:imageRef];
  • 原图

    4887王中王鉄算盘奖结果 10原图

  • “怀旧”效果图

    4887王中王鉄算盘奖结果 11“怀旧”效果图

  • 代码如下

viewDidLoad 中的代码和“简单的毛玻璃效果”中的 viewDidLoad 是一样的,这里也只贴出 button 被点击调用的代码

 CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [[CIImage alloc] initWithImage:self.imageView.image]; // 怀旧 CIPhotoEffectInstant // 单色 CIPhotoEffectMono // 黑白 CIPhotoEffectNoir // 褪色 CIPhotoEffectFade // 色调 CIPhotoEffectTonal // 冲印 CIPhotoEffectProcess // 岁月 CIPhotoEffectTransfer // 铬黄 CIPhotoEffectChrome CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectInstant"]; [filter setValue:inputImage forKey:kCIInputImageKey]; CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]]; UIImage *resultImage = [UIImage imageWithCGImage:cgImage]; self.imageView.image= [UIImage imageWithCGImage:resultImage.CGImage];

这是今晚整理的 CoreImage 相关的知识,如果哪里写的有问题,欢迎大家指正!另外给大家分享一篇文章,里面有很多 iOS 9 出来的 Core Image新滤镜,在这里。

本文由4887王中王鉄算盘奖结果发布于操作系统,转载请注明出处:代码笔记,模糊视图

关键词:

最火资讯