zoukankan      html  css  js  c++  java
  • 山寨"每日故宫"应用的图层遮罩效果

    山寨"每日故宫"应用的图层遮罩效果

    最终效果:

    应用中的效果:

    素材图片:

    源码:

    //
    //  ViewController.m
    //  每日故宫
    //
    //  Created by XianMingYou on 15/3/30.
    //  Copyright (c) 2015年 XianMingYou. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic, strong) UIImageView *bgImageView;
    @property (nonatomic, assign) CGRect       leftRect;
    @property (nonatomic, assign) CGRect       rightRect;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 背景view
        self.bgImageView        = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
        self.bgImageView.center = self.view.center;
        [self.view addSubview:self.bgImageView];
        
        // 存储必要的frame值
        CGRect  midRect = self.bgImageView.frame;
        CGFloat offsetX = 20.f;
        self.leftRect   = CGRectMake(midRect.origin.x - offsetX,
                                     midRect.origin.y,
                                     midRect.size.width,
                                     midRect.size.height);
        self.rightRect  = CGRectMake(midRect.origin.x + offsetX,
                                     midRect.origin.y,
                                     midRect.size.width,
                                     midRect.size.height);
        
        // 加载图片
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"31"]];
        imageView.frame        = self.view.bounds;
        [self.view addSubview:imageView];
        
        
        // 执行动画
        [self animationBGImageViewWithDirection:YES];
    }
    
    - (void)animationBGImageViewWithDirection:(BOOL)left {
        [UIView animateWithDuration:2.f animations:^{
            if (left == YES) {
                self.bgImageView.frame = self.rightRect;
            } else {
                self.bgImageView.frame = self.leftRect;
            }
        } completion:^(BOOL finished) {
            [self animationBGImageViewWithDirection:!left];
        }];
    }
    
    @end
  • 相关阅读:
    [VBA]根据身份证号码计算年龄的Excel函数
    [VBA]发布一个计算桩号之差的Excel自定义函数(VBA)
    [VBA]用一个简单例子说明如何在Excel中自定义函数
    元素定位工具:Chrome浏览器ChroPath插件
    68 个 Python 内置函数
    Python错误重试
    jenkins 中展示漂亮的 HTML 测试报告
    python解决接口数据使用了RSA加密和签名
    Python装饰器用法
    Pycharm中文版教程
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4377584.html
Copyright © 2011-2022 走看看