您的位置:首页 > 其它

用于mask遮罩效果的图片配合resizableImage使用

2015-03-30 21:32 120 查看
用于mask遮罩效果的图片配合resizableImage使用



效果:



作为素材用的图片:





源码:

//
//  ViewController.m
//  Rect
//
//  Created by YouXianMing on 15/3/29.
//  Copyright (c) 2015年 YouXianMing. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

// 背景图
UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"psb.jpeg"]];
bgView.frame        = CGRectMake(0, 0,
bgView.frame.size.width / 2.f,
bgView.frame.size.height / 2.f);
bgView.center       = self.view.center;
[self.view addSubview:bgView];

// 作为mask用的图片
UIImage *maskImage   = [UIImage imageNamed:@"rect_new"];
maskImage            = [maskImage resizableImageWithCapInsets:UIEdgeInsetsMake(13, 13, 13, 13)
resizingMode:UIImageResizingModeTile];

// 作为mask用的view
UIImageView *maskView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
maskView.image        = maskImage;
bgView.maskView       = maskView;

// 执行动画
[UIImageView animateWithDuration:3.f animations:^{
maskView.frame = bgView.bounds;
}];
}

@end


需要注意的细节:



这对于做alpha通道的渐变效果十分便利。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: