JZtvOSParallaxButton 0.1.6

JZtvOSParallaxButton 0.1.6

测试已经测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年12月

Justin Fincher维护。



简介

https://github.com/JustinFincher/JZtvOSParallaxButton/blob/master/DemoPic/JPG.jpg
中文 / 英文
具有视差效果的 tvOS 按钮(ObjC)。
Apple TV HIG 有一个视频
这是一个尝试相似效果的按钮。具有反射光,长按可启用视差模式,长按可关闭。
DemoGif
https://github.com/JustinFincher/JZtvOSParallaxButton/blob/master/DemoPic/GIF.gif

使用方法

#import "JZParallaxButton.h"

..... //TL;DR


NSMutableArray *Layers = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"Layer1"],[UIImage imageNamed:@"Layer2"],[UIImage imageNamed:@"Layer3"],[UIImage imageNamed:@"Layer4"], nil];

    JZParallaxButton *NewPB = [[JZParallaxButton alloc] initButtonWithCGRect:YourRect
                                                              WithLayerArray:Layers
                                                      WithRoundCornerEnabled:YES
                                                   WithCornerRadiusifEnabled:5.0f
                                                          WithRotationFrames:100
                                                        WithRotationInterval:3.0f];


    [self.view addSubview:NewPB];

WithLayerArray:NSArray,UIImage 数组,记住数组中图像的索引应从底部到顶部。
WithRoundCornerEnabled:BOOL
WithCornerRadiusifEnabled:CGFloat
WithRotationFrames:int,如果按钮自身旋转一周,则应渲染多少帧。
WithRotationInterval:CGFloat,按钮自身旋转一周需要多少秒。
(提示:WithRotationInterval/WithRotationFrames 指示旋转和位置持续的时间,通常应小于 1/24,或者使用任何 RotateMethodType,则旋转动画将滞后)

您还可以调整这些参数
ScaleBase:CGFloat,默认 1.0f。长按时,按钮会略微放大,这是缩放的程度。
ScaleAddition:CGFloat,默认 1.0f。长按时,按钮还将放大视差图像层以实现透视效果,ScaleAddition 调整此值。
isParallax:BOOL,指示按钮的状态。

ParallaxMethod:ENUM,3 个选项,这将改变深度效果

typedef NS_ENUM(NSInteger, ParallaxMethodType)  
{  
    ParallaxMethodTypeLinear = 0, //Default  
    ParallaxMethodTypeEaseIn, //Use this when your want your foreground layer parallax more  
    ParallaxMethodTypeEaseOut, //Use this when your want your background layer parallax more  
};  

RotateMethodType:ENUM,3 个选项,这将改变旋转效果是否自动,或随手指移动而改变。

typedef NS_ENUM(NSInteger, RotateMethodType)
{
    RotateMethodTypeAutoRotate = 0, //Default
    RotateMethodTypeWithFinger, //Rotation for the direction where finger at.
    RotateMethodTypeWithFingerReverse, //Rotation for the opposite direction where finger at.
};

还有以下这些(在 JZParallaxButton.m 中定义)
RotateParameter CGFloat,默认 0.4。旋转角度参数。
SpotlightOutRange CGFloat,默认 5.0f。表示从按钮中心到反射光距离。

要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install
JZViewController.m 包含 3 个视差按钮、2 张海报和 1 个图标。移除 // 中的 addSubview 以查看。

安装

JZtvOSParallaxButton 可通过 CocoaPods 获得。要安装,请简单地在 Podfile 中添加以下行

pod "JZtvOSParallaxButton"

或者,抓取 JZParallaxButton.h 和 .m,编辑 .m 文件

SpotLightView.image = [UIImage imageNamed:@"Spotlight" inBundle:bundle compatibleWithTraitCollection:nil];

使用

SpotLightView.image = [UIImage imageNamed:@"Spotlight"];

然后从 这里 抓取 Spotlight.png

待办事项

1. 添加3D触控支持。

作者

Fincher Justin, [email protected]

许可证

JZtvOSParallaxButton 在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。

中文

JZtvOSParallaxButton 是一个模仿Apple TV中三维视差按钮的UIButton。
这个按钮初始化时是普通样式,长按后可以开启如同苹果设计规范的自转效果,同时可以看到分层的三维效果。长按即可回到普通样式。

用法: 同用法说明
WithLayerArrayNSArray,包含UIImage的数组,图层的排序应该是从下往上进行addObject
WithRoundCornerEnabledBOOL,是否启用圆角(推荐,看起来更美观)。
WithCornerRadiusifEnabledCGFloat,圆角的半径。
WithRotationFramesint,自转一周要用多少帧(这里说的不太严谨,其实指的不是帧速率,而是按钮自己一周要做多少次3D变换的动画)。
WithRotationIntervalCGFloat,自转一周要多少秒。
(建议: WithRotationInterval/WithRotationFrames 表示一帧保持多少秒,一般这个数字应该小于1/24,否则对于任何RotateMethodType整个动画都会显得很卡)

还有以下参数:
ScaleBaseCGFloat,默认1.0f。长按时,有一个放大动画,这个可以改变放大多少,不过默认1.0就够了。
ScaleAdditionCGFloat,默认1.0f。长按后,每个图层都会有或多或少的放大(用于制造远小近大的透视效果),该参数调节图层的放大多少。
isParallaxBOOL,通过这个读取当前状态,应该是只读的,但没有任何限制。

ParallaxMethod:枚举,3个选择,用于改变透视的深度效果。

typedef NS_ENUM(NSInteger, ParallaxMethodType)  
{  
    ParallaxMethodTypeLinear = 0, //默认  
    ParallaxMethodTypeEaseIn, //如果想要前排的图层视差效果更好些    
    ParallaxMethodTypeEaseOut, //如果想要后排的图层视差效果更好些    
};  

RotateMethodType:枚举,3个选择,改变自转效果是自动的,还是跟随手指。

typedef NS_ENUM(NSInteger, RotateMethodType)
{  
    RotateMethodTypeAutoRotate = 0, //默认    
    RotateMethodTypeWithFinger, //按钮向手指按下的地方转动  
    RotateMethodTypeWithFingerReverse, //按钮向手指按下的反方向转动  
};  

还有以下:(在JZParallaxButton.m中定义)
RotateParameterCGFloat,默认0.4。自转时角度参数。
SpotlightOutRangeCGFloat,默认5.0f。高光和按钮中心的距离(最好调大一点,这样看起来更真实,4.0-7.0f差不多)。