iOS 仿韩服LOL周免英雄展示

最近在玩韩服,看到首页的一块动画蛮有意思的,仿写一下,O(∩_∩)O哈哈~

基本功能已经实现,还有些细节,等有空的时候补充 0.0

注释也后补,不是专业UI,图截的有点挫~~~ 

.h文件

@interfaceWsView :UIView

@property(nonatomic,assign)NSIntegerbtnTag;

@end

.m文件

#define WIDTHDiv[UIScreen mainScreen ].bounds.size.width

#define HEIGHTDiv[ UIScreen mainScreen ].bounds.size.height

#import"WsView.h"

@interfaceWsView()

@property(nonatomic,assign)BOOLleftHid;

@property(nonatomic,assign)BOOLrightHid;

@end

@implementationWsView

- (instancetype)initWithFrame:(CGRect)frame

{

self= [superinitWithFrame:frame];

if(self) {

self.btnTag=6;

self.leftHid=NO;

self.rightHid=NO;

for(inti =0; i <9; i++) {

UIButton*img = [UIButtonnew];

img.clipsToBounds=YES;

img.tag= i+100;

[imgsetImage:[UIImageimageNamed:[NSStringstringWithFormat:@"LOLIMage_%d_02.jpg",i]]forState:UIControlStateNormal];

img.imageView.contentMode=UIViewContentModeScaleAspectFill;

[imgaddTarget:selfaction:@selector(imgBtnClick:)forControlEvents:UIControlEventTouchUpInside];

[selfaddSubview:img];

}

for(inti =0; i <2; i++) {

UIButton*btn = [UIButtonnew];

btn.tag= i+1000;

[btnaddTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];

[btnsetImage:[UIImageimageNamed:i==1?@"left":@"right"]forState:UIControlStateNormal];

[selfaddSubview:btn];

}

}

returnself;

}

-(void)btnClick:(UIButton*)senter{

if(senter.tag!=1000) {

self.btnTag--;

if(self.btnTag==0) {

self.leftHid=YES;

}else{

self.rightHid=NO;

}

}else{

self.btnTag++;

if(self.btnTag==8) {

self.rightHid=YES;

}else{

self.leftHid=NO;

}

}

[selfsetNeedsLayout];

}

-(void)imgBtnClick:(UIButton*)senter{

if(senter.tag==100) {

self.leftHid=YES;

self.rightHid=NO;

}elseif(senter.tag==108) {

self.rightHid=YES;

self.leftHid=NO;

}else{

self.rightHid=NO;

self.leftHid=NO;

}

self.btnTag= senter.tag-100;

[selfsetNeedsLayout];

}

-(void)layoutSubviews{

[superlayoutSubviews];

for(inti =0; i <2; i++) {

UIButton*btn = [selfviewWithTag:i+1000];

btn.frame=CGRectMake(WIDTHDiv-90-(i*50),55,40,40);

if(i !=0) {

if(self.leftHid) {

CGRectrect = btn.frame;

rect.size.width=0;

rect.size.height=0;

CGPointpoint = btn.center;

[UIViewanimateWithDuration:.3animations:^{

btn.frame= rect;

btn.center= point;

}];

}else{

CGRectrect = btn.frame;

rect.size.width=40;

rect.size.height=40;

CGPointpoint = btn.center;

[UIViewanimateWithDuration:.3animations:^{

btn.frame= rect;

btn.center= point;

}];

}

}else{

if(self.rightHid) {

CGRectrect = btn.frame;

rect.size.width=0;

rect.size.height=0;

CGPointpoint = btn.center;

[UIViewanimateWithDuration:.3animations:^{

btn.frame= rect;

btn.center= point;

}];

}else{

CGRectrect = btn.frame;

rect.size.width=40;

rect.size.height=40;

CGPointpoint = btn.center;

[UIViewanimateWithDuration:.3animations:^{

btn.frame= rect;

btn.center= point;

}];

}

}

}

for(inti =0; i <9; i++) {

UIButton*img = [selfviewWithTag:i+100];

if(i

[UIViewanimateWithDuration:.3animations:^{

img.frame=CGRectMake(i*66,100,66,HEIGHTDiv*.5);

}];

}

if(i ==self.btnTag) {

[UIViewanimateWithDuration:.3animations:^{

img.frame=CGRectMake(i*66,100,WIDTHDiv-8*66,HEIGHTDiv*.5);

}];

}

if(i >self.btnTag) {

[UIViewanimateWithDuration:.3animations:^{

img.frame=CGRectMake(i*66+(WIDTHDiv-9*66),100,66,HEIGHTDiv*.5);

}];

}

}

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、设置UILabel行间距 NSMutableAttributedString*attrString=[[NSM...
    iOS祎阅读 2,233评论 0 0
  • 转自:http://www.code4app.com/blog-866962-1317.html1、设置UILab...
    MMOTE阅读 1,700评论 1 1
  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 810评论 0 3
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 1,741评论 0 3
  • 去日本旅游可以有很多种原因:购物、美食、美景、街景、铁道。 不知何时,我也迷上了日本的铁道,每次去都要拍上几张。像...
    老扬阅读 861评论 2 8