貌似经常会用到,自己整理收藏起来,方便日后查找备用。

效果如图:

由于制作gif,调整了属性,所以看起来的效果不好。如果用默认配置,生成的gif会很大。

制作gif:

1.使用QuickTimePlayer ,mac上插上iPhone, 然后进行屏幕录制,但是要选择插上的iPhone,然后会自动在Mac弹出同步的iPhone屏幕,点击录制。

2.使用GIFBrewery,选中录制文件*.mov, 进行生成gif。

代码如下:

#import "XPBaseView.h"

@protocol XPDetailTabBarViewDelegate;

@interface XPDetailTabBarView : XPBaseView

@property (nonatomic,weak) id<XPDetailTabBarViewDelegate> delegate;
/**
* 是否是双语
*/
@property (nonatomic,assign) BOOL isBilingual;
/**
* 是否点赞
*/
@property (nonatomic,assign) BOOL isLike; @end @protocol XPDetailTabBarViewDelegate <NSObject> @optional
- (void)XPDetailTabBarView:(XPDetailTabBarView*)view clickIndex:(NSInteger)index; @end

  

#import "XPDetailTabBarView.h"

@interface XPDetailTabBarView ()

@property (nonatomic,strong) NSArray *dataImages;
@property (nonatomic,strong) UIView *moveView;
@property (nonatomic,assign) NSInteger moveIndex; @end @implementation XPDetailTabBarView -(void)initData{ } -(void)initSubViews{
self.dataImages = @[@"detail_tab_english",@"icon_like",@"detail_tab_recording",@"detail_tab_quiz",@"detail_tab_myrecord"]; CGFloat itemWidth = SCREEN_WIDTH / self.dataImages.count;
CGFloat itemHeight = 44; self.moveView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, itemWidth, itemWidth)];
self.moveView.backgroundColor = AppStyleThemeOrangeColor;
[self addSubview:self.moveView]; for (int i = 0; i<self.dataImages.count; i++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = 20000+i;
button.frame = CGRectMake(i*itemWidth, 0, itemWidth, itemHeight);
button.backgroundColor = [UIColor clearColor];
[button setImage:[UIImage imageNamed:[self.dataImages objectAtIndex:i]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
} -(void)setMoveIndex:(NSInteger)moveIndex{ NSInteger animationType = 1;//1左,2右
if(moveIndex > _moveIndex){
animationType = 2;
} _moveIndex = moveIndex; CGFloat itemWidth = SCREEN_WIDTH / self.dataImages.count;
CGFloat itemHeight = 44; CGRect rect = CGRectMake(moveIndex*itemWidth, 0, itemWidth, itemHeight); WS(weakSelf)
[UIView animateWithDuration:0.2 animations:^{
if (animationType == 2){//右
weakSelf.moveView.frame = CGRectMake(rect.origin.x+2, rect.origin.y, rect.size.width, rect.size.height);
} else if (animationType == 1){//左
weakSelf.moveView.frame = CGRectMake(rect.origin.x-2, rect.origin.y, rect.size.width, rect.size.height);
}
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
if (animationType == 2){//右
weakSelf.moveView.frame = CGRectMake(rect.origin.x-5, rect.origin.y, rect.size.width, rect.size.height);
} else if (animationType == 1){//左
weakSelf.moveView.frame = CGRectMake(rect.origin.x+5, rect.origin.y, rect.size.width, rect.size.height);
}
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.4 animations:^{
weakSelf.moveView.frame = rect;
} completion:^(BOOL finished) { }];
}];
}];
} - (void)setIsBilingual:(BOOL)isBilingual{
_isBilingual = isBilingual; UIButton *button = [self viewWithTag:20000];
if(isBilingual){
[button setImage:[UIImage imageNamed:@"detail_tab_english"] forState:UIControlStateNormal];
}else{
[button setImage:[UIImage imageNamed:@"detail_tab_bilingual"] forState:UIControlStateNormal];
}
} - (void)setIsLike:(BOOL)isLike{
_isLike = isLike; UIButton *button = [self viewWithTag:20001];
if(isLike){
[button setImage:[UIImage imageNamed:@"icon_like_selected"] forState:UIControlStateNormal];
}else{
[button setImage:[UIImage imageNamed:@"icon_like"] forState:UIControlStateNormal];
}
} - (void)buttonClicked:(UIButton*)button{
NSInteger index = button.tag - 20000; self.moveIndex = index; if(self.delegate && [self.delegate respondsToSelector:@selector(XPDetailTabBarView:clickIndex:)]){
[self.delegate XPDetailTabBarView:self clickIndex:index];
}
}
@end

  

iOS 自定义滑动切换TabBar的更多相关文章

  1. iOS 自定义滑动切换TabbarItem 觉得设计丑也要做出来的UI效果。。。

    UI丑却要继续做的感言: 对UI不满意的时候,就会觉得丑爆了,时间长了,却丑习惯了. 论前一阵子Tabbar 多丑,丑得最后不要tabbar了...但是自定义tabbar 和遇到的问题解决的过程可以记 ...

  2. IOS自定义场景切换动画。

    IOS中我们可以通过Storyborad以及segue来实现我们自己的场景切换动画,新建项目使用Single View Application模板并取名为MyCustomSegue. 使用storyb ...

  3. iOS 自定义UITabBarController的tabBar

               #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDeleg ...

  4. iOS开发之多表视图滑动切换示例(仿"头条"客户端)---优化篇

    前几天发布了一篇iOS开发之多表视图滑动切换示例(仿"头条"客户端)的博客,之所以写这篇博客,是因为一位iOS初学者提了一个问题,简单的写了个demo做了个示范,让其在基础上做扩展 ...

  5. Android自定义顶部栏及侧滑菜单和fragment+viewpag滑动切换的实现

    嘿嘿嘿,关于android滑动的操作,是不是经常都会用到呢. 我肯定也要学习一下啦. https://blog.csdn.net/u013184970/article/details/82882107 ...

  6. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  7. iOS彩票项目--第五天,新特性引导页的封装、返回按钮的自定义、导航控制器的滑动返回以及自定义滑动返回功能

    一.上次实现了在AppDelegate中通过判断app版本决定是否进入新特性页面,今天将AppDelegate中的一坨进行了封装.将self.window的根控制器到底应该为新特性界面,还是主页面,封 ...

  8. WPF 自定义滑动ScrollViewer

    自定义滑动滚动条 预期目标:横向滚动条,可以左右滑动,用鼠标按住(触摸)然后释放可以实现快速滑动. 我们有几种方案: 1.ScrollViewer,修改其中的横向滚动条,将其中的背景设置为透明. 但是 ...

  9. FlexSlider jQuery滑动切换插件 参数

    demo:http://www.sucaihuo.com/jquery/0/6/demo/ FlexSlider是一个非常出色的jQuery滑动切换插件,它支持所有主流浏览器,并有淡入淡出效果.适合所 ...

随机推荐

  1. Robots on a grid(DP+bfs())

    链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Ro ...

  2. 数据库知识整理<七>

    组合查询: 7.1使用子查询: 嵌套在其他查询中的查询,我们称之为子查询.子查询本身也可能包含一个子查询.子查询也称为内部查询,而包含子查询的语句也称为外部查询. 所有的子查询可以被分为两个类别:子查 ...

  3. Ascii Design 1.0.2,好玩的 ASCII 字符设计工具

    Ascii Design 1.0.2 可检查系统是否已安装 figlet 包(对非 Windows 用户),对代码做了一些改进,修复了使用 Qt 4.8.x 时的编译警告信息. Ascii Desig ...

  4. JS DOM操作

    一.DOM基础 1.节点(node)层次 Document--最顶层的节点,所有的其他节点都是附属于它的. DocumentType--DTD引用(使用<!DOCTYPE>语法)的对象表现 ...

  5. SharePoint 2013 REST 以及 OData 基础

    这篇文章会介绍: 简单的介绍REST,OData OData实现细节 OData在SharePoint 2013中的实现 为什么REST很重要 过去几年基于REST的webservice在IT企业越来 ...

  6. 使用Lucene.NET实现数据检索功能

    引言     在软件系统中查询数据是再平常不过的事情了,那当数据量非常大,数据存储的媒介不是数据库,或者检索方式要求更为灵活的时候,我们该如何实现数据的检索呢?为数据建立索引吧,利用索引技术可以更灵活 ...

  7. AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)

    Fork() in C: (sys_fork.c) #include <stdio.h> #include <stdlib.h> #include <unistd.h&g ...

  8. 给同为.NET开发者普及一点Oracle数据库经验

    前段时间,因为要给自己开发的搜易站内搜索引擎增加Oracle数据库的支持,所以学习了下Oracle的基础知识,发现使用方式跟MYSQL,MSSQL等数据库的思维有很大的不同,总结一下几点不同,希望给初 ...

  9. 采用TL026等构成的宽带ALC放大器电路图

    Building a Differential Amplifier An op-amp with no feedback is already a differential amplifier, am ...

  10. windows7文件共享

    工作组模式下: 参考:http://support.microsoft.com/kb/2533010/zh-cn 1.首先区分网络类型配置文件:家庭网络,工作网络还是公用网络 2.每种类型区分两种文件 ...