山寨凤凰新闻菜单效果

简介:

山寨凤凰新闻菜单效果

 

效果图:

 

山寨来源:

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

目录
相关文章
|
传感器 存储 算法
抱歉,Xposed真的可以为所欲为——3.微信运动占领封面出售广告位
简单的二十行代码,利用Xposed Hook掉计步传感器,以此达到刷步数的目的。
589 0
|
5G 流计算 芯片
华为折叠屏手机Mate X宣传海报曝光 有望近期开售
早在今年2月的MWC 2019大展上,华为推出的首款折叠屏新机Mate X就博取了众多目光。极具想象力的鹰翼式折叠设计,开合随心自由变幻,一举荣获“MWC 2019最佳新联接移动终端奖”。
247 0
华为折叠屏手机Mate X宣传海报曝光 有望近期开售
|
存储 编解码
钛客全息手机正式发布 虚空显示功能碉堡了
钛客全息手机正式发布 虚空显示功能碉堡了
454 0
「镁客早报」华为称将如期推出折叠屏手机;马斯克与SEC达成和解,称发推特经过律师同意
波音737 MAX最快5月底复飞,软件更新已完成;中国电信开启2019“携号转网”扩容改造集采。
303 0
|
人工智能 安全 机器人
央视新闻入驻B站;果冻有家:租房场景中的共享社交融合
央视新闻入驻B站;果冻有家:租房场景中的共享社交融合
664 0
下一篇
无影云桌面