• 山寨凤凰新闻菜单效果


     山寨凤凰新闻菜单效果

     

    效果图:

     

    山寨来源:

    LiveScaleLabel.h 与 LiveScaleLabel.m
    //
    //  LiveScaleLabel.h
    //  ShowLabel
    //
    //  Created by XianMingYou on 15/1/26.
    //  Copyright (c) 2015年 XianMingYou. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface LiveScaleLabel : UIView
    
    @property (nonatomic) CGFloat beginScaleValue;
    @property (nonatomic) CGFloat endScaleValue;
    
    @property (nonatomic, strong) UIColor  *normalStateColor;
    @property (nonatomic, strong) UIColor  *maxStateColor;
    
    @property (nonatomic, strong) NSString *text;
    @property (nonatomic, strong) UIFont   *font;
    
    @property (nonatomic) CGFloat sensitiveValue; // 敏感的值
    @property (nonatomic) CGFloat currentValue;   // 当前值
    
    - (void)buildView;
    - (void)accessCurrentValue:(CGFloat)currentValue;
    
    @end
    //
    //  LiveScaleLabel.m
    //  ShowLabel
    //
    //  Created by XianMingYou on 15/1/26.
    //  Copyright (c) 2015年 XianMingYou. All rights reserved.
    //
    
    #import "LiveScaleLabel.h"
    
    @interface LiveScaleLabel ()
    
    @property (nonatomic, strong) UILabel *label;
    @property (nonatomic, strong) UIView  *snapView;
    @property (nonatomic, strong) UILabel *maxLabel;
    
    @end
    
    @implementation LiveScaleLabel
    
    - (instancetype)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            [self setUpLabelWithFrame:self.bounds];
        }
        
        return self;
    }
    
    - (void)setUpLabelWithFrame:(CGRect)frame {
        self.label                  = [[UILabel alloc] initWithFrame:frame];
        self.label.textAlignment    = NSTextAlignmentCenter;
        
        self.maxLabel               = [[UILabel alloc] initWithFrame:frame];
        self.maxLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    - (void)buildView {
        UIColor *normalStateColor = (self.normalStateColor == nil ? [UIColor blackColor] : self.normalStateColor);
        UIColor *maxStateColor    = (self.maxStateColor == nil ? [UIColor redColor] : self.maxStateColor);
        UIFont  *font             = (self.font == nil ? [UIFont systemFontOfSize:16.f] : self.font);
        NSString *text            = (self.text == nil ? @"" : self.text);
        
        // 设置基本样式
        self.label.text      = text;
        self.label.textColor = normalStateColor;
        self.label.font      = font;
        
        self.maxLabel.text      = text;
        self.maxLabel.textColor = maxStateColor;
        self.maxLabel.font      = font;
        
        // 截图
        [self addSubview:self.label];
        [self addSubview:self.maxLabel];
        
        // 设定起始状态值
        [self accessCurrentValue:self.currentValue];
    }
    
    - (void)accessCurrentValue:(CGFloat)currentValue {
        CGFloat beginScaleValue = (self.beginScaleValue <= 0 ? 1.f : self.beginScaleValue);
        CGFloat endScaleValue   = (self.endScaleValue   <= 0 ? 1.f : self.endScaleValue);
        CGFloat sensitiveValue  = (self.sensitiveValue  <= 0 ? 320 : self.sensitiveValue);
        
        CGFloat percent = currentValue / sensitiveValue;
        if (percent >= 1) {
            percent = 1;
        } else if (percent <= 0) {
            percent = 0;
        }
        
        self.transform      = CGAffineTransformMake(beginScaleValue + percent * endScaleValue, 0, 0,
                                                    beginScaleValue + percent * endScaleValue, 0, 0);
        self.maxLabel.alpha = percent;
        self.label.alpha    = 1 - percent;
    }
    
    @end
    //
    //  ViewController.m
    //  ShowLabel
    //
    //  Created by XianMingYou on 15/1/26.
    //  Copyright (c) 2015年 XianMingYou. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "LiveScaleLabel.h"
    
    @interface ViewController ()<UIScrollViewDelegate>
    
    @property (nonatomic, strong) UIScrollView   *scrollView;
    @property (nonatomic, strong) LiveScaleLabel *liveLabelLeft;
    @property (nonatomic, strong) LiveScaleLabel *liveLabelRight;
    @property (nonatomic, strong) UIView         *lineView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor blackColor];
        
        // 左侧view
        self.liveLabelLeft                  = [[LiveScaleLabel alloc] initWithFrame:CGRectMake(0, 300, 160, 30)];
        self.liveLabelLeft.normalStateColor = [UIColor grayColor];
        self.liveLabelLeft.text             = @"YouXianMing";
        self.liveLabelLeft.endScaleValue    = 0.2;
        self.liveLabelLeft.sensitiveValue   = 320;
        [self.liveLabelLeft buildView];
        [self.liveLabelLeft accessCurrentValue:320];
        [self.view addSubview:self.liveLabelLeft];
        
        // 右侧view
        self.liveLabelRight                  = [[LiveScaleLabel alloc] initWithFrame:CGRectMake(160, 300, 160, 30)];
        self.liveLabelRight.text             = @"NoZuoNoDie";
        self.liveLabelRight.normalStateColor = [UIColor grayColor];
        self.liveLabelRight.maxStateColor    = [UIColor cyanColor];
        self.liveLabelRight.endScaleValue    = 0.2;
        self.liveLabelRight.sensitiveValue   = 320;
        [self.liveLabelRight buildView];
        [self.view addSubview:self.liveLabelRight];
    
        
        self.scrollView                                = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        self.scrollView.delegate                       = self;
        self.scrollView.pagingEnabled                  = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.contentSize                    = CGSizeMake(self.scrollView.frame.size.width * 2,
                                                                    self.scrollView.frame.size.height);
        [self.view addSubview:self.scrollView];
        
        // 线条view
        self.lineView            = [[UIView alloc] initWithFrame:CGRectMake(0, 300 + 30, 160, 1)];
        UIView *backView         = [[UIView alloc] initWithFrame:CGRectMake(20, 0, 120, 1)];
        backView.backgroundColor = [UIColor yellowColor];
        [self.lineView addSubview:backView];
        [self.view addSubview:self.lineView];
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat x = scrollView.contentOffset.x;
        [self.liveLabelLeft  accessCurrentValue:320 - x];
        [self.liveLabelRight accessCurrentValue:x];
        
        CGRect rect = self.lineView.frame;
        rect.origin.x      = x / 2.f;
        self.lineView.frame = rect;
    }
    
    @end
  • 相关阅读:
    leetcode题解:Search in Rotated Sorted Array(旋转排序数组查找)
    leetcode 题解:Remove Duplicates from Sorted Array II(已排序数组去三次及以上重复元素)
    leetcode 题解:Remove Duplicates from Sorted Array(已排序数组去重)
    leetcode题解:Tree Level Order Traversal II (二叉树的层序遍历 2)
    leetcode 题解:Binary Tree Level Order Traversal (二叉树的层序遍历)
    c++ STL:队列queue、优先队列priority queue 的使用
    leetcode题解:Binary Tree Postorder Traversal (二叉树的后序遍历)
    算术表达式解析(第三版)词法分析版
    经典算法:牛顿迭代法求平方根
    进入游戏行业1年的总结
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4248860.html
Copyright © 2020-2023  润新知