zoukankan      html  css  js  c++  java
  • 用于mask遮罩效果的图片配合resizableImage使用

    用于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通道的渐变效果十分便利。

  • 相关阅读:
    C# Andriod AES 加密算法
    微软企业库的 注入和依赖&nbs…
    锐捷交换机RG-3760-24 的简单配置与VLAN搭建
    TCP-IP and Advanced Topics 课程总结与报告
    Network Security Threats
    Multicast Routing
    OpenFlow, SDN, and NFV
    Mobile IP
    数据结构:树的来源与定义
    TCP Congestion Control
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4375182.html
Copyright © 2011-2022 走看看