山寨凤凰新闻菜单效果

效果图:

山寨来源:

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
时间: 2024-08-08 01:10:22

山寨凤凰新闻菜单效果的相关文章

Android实现下拉导航选择菜单效果【转载地址:http://www.cnblogs.com/hanyonglu/archive/2012/07/31/2617488.html】

本文介绍在Android中如何实现下拉导航选择菜单效果.   关于下拉导航选择菜单效果在新闻客户端中用的比较多,当然也可以用在其他的项目中,这样可以很方便的选择更多的菜单.我们可以让我们的应用顶部有左右滑动或进行切换的导航菜单,也可以为了增强用户体验在应用中添加这样的下拉导航选择菜单效果. 关于它的实现原理,其实也是挺简单的,就是使用PopupWindow来进行展现,在显示时控制其高度并配置以相应的动画效果.在PopupWindow中我使用GridView来控制里面的菜单项,每个菜单项对应相应的

Android实现下拉导航选择菜单效果(转)

本文转载自互联网 关于下拉导航选择菜单效果在新闻客户端中用的比较多,当然也可以用在其他的项目中,这样可以很方便的选择更多的菜单.我们可以让我们的应用顶部有左右滑动或进行切换的导航菜单,也可以为了增强用户体验在应用中添加这样的下拉导航选择菜单效果. 关于它的实现原理,其实也是挺简单的,就是使用PopupWindow来进行展现,在显示时控制其高度并配置以相应的动画效果.在PopupWindow中我使用GridView来控制里面的菜单项,每个菜单项对应相应的图片和文字.当然了,也有其他的实现方式.为了

纯CSS实现的二级下拉菜单效果代码实例

纯CSS实现的二级下拉菜单效果代码实例:二级下拉是最为常用的效果之一,当前的此效果一般哟结合js实现,本章节介绍一个使用纯CSS实现的二级下拉菜单效果,希望能够给需要的朋友带来一定的帮助,不过此代码也有一点浏览器兼容问题,那就是在IE6中不兼容.代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" conten

Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭【学习鸿洋_视频博客笔记总结】

学习鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/39257409 学习鸿洋视频:慕课网视频 看看Android 高仿 QQ5.0 侧滑菜单效果 自定义控件实现效果: 技术上,继承HorizontalScrollView 加上自定义ViewGroup来实现: 1.onMeasure:决定内部View(子View)的宽和高,以及自己的宽和高 2.onLayout:决定子View的放置位置 3.onTouchEvent[监听动作] 自定

点击弹出弹性下拉菜单效果

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><meta name="keywords" content="站长,网页特效,js特效,广告代码,zzjs,zzjs.net,sky,www.zzjs.net,站长特效 网" /><meta name="

两个GridView之间数据转移,交互,实现拖拽,网易新闻列表效果实现

两个GridView之间数据转移,交互,实现拖拽,网易新闻列表效果实现 摘要 :android 高仿频道管理网易新闻. 新闻频道增删,排序,以及一些动画的实现 可拖动的GridView 地址  :  http://www.itnose.net/detail/6035345.html

实现ios常见菜单效果的思路

目前见过的实现边侧菜单的效果,比较流行的有以下三种:(效果图) 1.菜单栏覆盖在部分主视图上 附上实现该效果的一个不错的源码地址: http://code4app.com/ios/RNFrostedSidebar/524399706803fa3c33000001 (1)最开始要实现这个效果,我想最简单的方式就是:添加UIView,加上一个self.view大小的子视图,菜单列表以外的区域设为透明灰色.后来发现,如果当前的控制器有显示导航栏或者工具栏,这个子视图就无法遮盖住导航栏或者工具栏上面的按

jQuery小盒子菜单效果

jQuery小盒子菜单效果 程序吧推荐下载,小盒子方式菜单,效果酷毙了... jQuery小盒子菜单效果,布布扣,bubuko.com

很酷的伸缩导航菜单效果,可自定义样式和菜单项。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ