一个很好用的侧滑框架ICSDrawerController实现的 QQ 侧滑及换肤功能
使用ICSDrawerController 实现侧滑功能
在ICSDrawerController 第三方上做了修改实现,QQ 点击头像打开关抽屉头像渐变的效果

- (void)hiddenHeadView:(hiddenHeadViewBlock)block;
@property(nonatomic,copy) hiddenHeadViewBlock hiddenBlock;
- (void)hiddenHeadView:(hiddenHeadViewBlock)block
{
self.hiddenBlock = block;
}
在拖拽滑动的手势方法中监听滑动的方法中来改变透明度
- (void)panGestureRecognized:(UIPanGestureRecognizer *)panGestureRecognizer
{
NSParameterAssert(self.leftView);
NSParameterAssert(self.centerView); UIGestureRecognizerState state = panGestureRecognizer.state;
CGPoint location = [panGestureRecognizer locationInView:self.view];
CGPoint velocity = [panGestureRecognizer velocityInView:self.view]; switch (state) { case UIGestureRecognizerStateBegan:
self.panGestureStartLocation = location;//记录当前的位置
if (self.drawerState == ICSDrawerControllerStateClosed) {
[self willOpen];
}
else {
[self willClose];
}
break; case UIGestureRecognizerStateChanged: { //每次拖拽滑动
CGFloat delta = 0.0f;
if (self.drawerState == ICSDrawerControllerStateOpening) {
delta = location.x - self.panGestureStartLocation.x;
}
else if (self.drawerState == ICSDrawerControllerStateClosing) {
delta = kICSDrawerControllerDrawerDepth - (self.panGestureStartLocation.x - location.x);
} CGRect l = self.leftView.frame;
CGRect c = self.centerView.frame;
if (delta > kICSDrawerControllerDrawerDepth) {
l.origin.x = 0.0f;
c.origin.x = kICSDrawerControllerDrawerDepth;
}
else if (delta < 0.0f) {
l.origin.x = kICSDrawerControllerLeftViewInitialOffset;
c.origin.x = 0.0f;
}
else {
// While the centerView can move up to kICSDrawerControllerDrawerDepth points, to achieve a parallax effect
// the leftView has move no more than kICSDrawerControllerLeftViewInitialOffset points
l.origin.x = kICSDrawerControllerLeftViewInitialOffset
- (delta * kICSDrawerControllerLeftViewInitialOffset) / kICSDrawerControllerDrawerDepth; c.origin.x = delta;
CGFloat alpha = - delta//2.6;
if (alpha > 1.0) {
alpha = 1.0;
}else if(alpha < ){
alpha = ;
}
//头像是否显示隐藏
self.hiddenBlock(alpha);
} self.leftView.frame = l;
self.centerView.frame = c; break;
} case UIGestureRecognizerStateEnded: { //拖拽结束 if (self.drawerState == ICSDrawerControllerStateOpening) {
CGFloat centerViewLocation = self.centerView.frame.origin.x;
if (centerViewLocation == kICSDrawerControllerDrawerDepth) {
// Open the drawer without animation, as it has already being dragged in its final position
[self setNeedsStatusBarAppearanceUpdate];
[self didOpen];
}
else if (centerViewLocation > self.view.bounds.size.width /
&& velocity.x > 0.0f) {
// Animate the drawer opening
[self animateOpening];
}
else {
// Animate the drawer closing, as the opening gesture hasn't been completed or it has
// been reverted by the user
[self didOpen];
[self willClose];
[self animateClosing];
} } else if (self.drawerState == ICSDrawerControllerStateClosing) {
CGFloat centerViewLocation = self.centerView.frame.origin.x;
if (centerViewLocation == 0.0f) {
// Close the drawer without animation, as it has already being dragged in its final position
[self setNeedsStatusBarAppearanceUpdate];
[self didClose];
}
else if (centerViewLocation < ( * self.view.bounds.size.width) /
&& velocity.x < 0.0f) {
// Animate the drawer closing
[self animateClosing];
}
else {
// Animate the drawer opening, as the opening gesture hasn't been completed or it has
// been reverted by the user
[self didClose]; // Here we save the current position for the leftView since
// we want the opening animation to start from the current position
// and not the one that is set in 'willOpen'
CGRect l = self.leftView.frame;
[self willOpen];
self.leftView.frame = l; [self animateOpening];
}
}
}
break; default:
break;
}
} #pragma mark - Animations
#pragma mark Opening animation
- (void)animateOpening
{
NSParameterAssert(self.drawerState == ICSDrawerControllerStateOpening);
NSParameterAssert(self.leftView);
NSParameterAssert(self.centerView); // Calculate the final frames for the container views
CGRect leftViewFinalFrame = self.view.bounds;
CGRect centerViewFinalFrame = self.view.bounds;
centerViewFinalFrame.origin.x = kICSDrawerControllerDrawerDepth; [UIView animateWithDuration:kICSDrawerControllerAnimationDuration
delay:
usingSpringWithDamping:kICSDrawerControllerOpeningAnimationSpringDamping
initialSpringVelocity:kICSDrawerControllerOpeningAnimationSpringInitialVelocity
options:UIViewAnimationOptionCurveLinear
animations:^{
self.centerView.frame = centerViewFinalFrame;
self.leftView.frame = leftViewFinalFrame;
self.hiddenBlock(); [self setNeedsStatusBarAppearanceUpdate];
}
completion:^(BOOL finished) {
[self didOpen];
}];
}
#pragma mark Closing animation
- (void)animateClosing
{
NSParameterAssert(self.drawerState == ICSDrawerControllerStateClosing);
NSParameterAssert(self.leftView);
NSParameterAssert(self.centerView); // Calculate final frames for the container views
CGRect leftViewFinalFrame = self.leftView.frame;
leftViewFinalFrame.origin.x = kICSDrawerControllerLeftViewInitialOffset;
CGRect centerViewFinalFrame = self.view.bounds; [UIView animateWithDuration:kICSDrawerControllerAnimationDuration
delay:
usingSpringWithDamping:kICSDrawerControllerClosingAnimationSpringDamping
initialSpringVelocity:kICSDrawerControllerClosingAnimationSpringInitialVelocity
options:UIViewAnimationOptionCurveLinear
animations:^{
self.centerView.frame = centerViewFinalFrame;
self.leftView.frame = leftViewFinalFrame;
self.hiddenBlock(); [self setNeedsStatusBarAppearanceUpdate];
}
completion:^(BOOL finished) {
[self didClose];
}];
}
给当前类扩充一个方法,拿到当前conroller的menuController
@interface UIViewController (ICSDrawerController) //拿到当前conroller的menuController
//如果不存在,返回nil
@property (nonatomic, readonly) ICSDrawerController* menuController; @end
@implementation UIViewController (ICSDrawerController)
- (ICSDrawerController *)menuController {
if (self.parentViewController == nil) {
return nil;
}else if ([self.parentViewController isKindOfClass:[ICSDrawerController class]]) {
return (ICSDrawerController* )self.parentViewController;
}else {
return self.parentViewController.menuController;
}
}
@end
换皮肤功能使用 KVO 监听属性就可以实现,这里附上代码https://github.com/SummerHH/QQMenu
一个很好用的侧滑框架ICSDrawerController实现的 QQ 侧滑及换肤功能的更多相关文章
- qt之窗口换肤(一个qss的坑:当类属性发现变化时需要重置qss,使用rcc资源文件)
1.相关文章 Qt 资源系统qt的moc,uic,rcc命令的使用 2.概要 毕业两年了,一直使用的是qt界面库来开发程序,使用过vs08.10.13等开发工具,并安装了qt的插件,最近在做客户 ...
- python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- 前端JavaScript(1) --Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- 关于引入多个jquery冲突的问题(附一个很好用的validate前端验证框架及使用方法)
废话不多说,进入正题: 如果一个jsp中想要使用两个不同版本的jquery怎么办呢?客官往下看: <script src="${ctxStatic}/jquery/jquery-1.8 ...
- 一个标准的,兼容性很好的div仿框架的基础模型!
<!DOCTYPE html> <html > <head> <meta http-equiv="Content-Type" conten ...
- JDBC数据源(DataSource)数据源技术是Java操作数据库的一个很关键技术,流行的持久化框架都离不开数据源的应用。
JDBC数据源(DataSource)的简单实现 数据源技术是Java操作数据库的一个很关键技术,流行的持久化框架都离不开数据源的应用. 2.数据源提供了一种简单获取数据库连接的方式,并能在内部通 ...
- Android开源框架之SwipeListView导入及模拟QQ侧滑
SwipeListView是Github上的一个开源框架,地址:https://github.com/47deg/android-swipelistview SwipeListView was bor ...
- 如何创建一个简单的C++同步锁框架(译)
翻译自codeproject上面的一篇文章,题目是:如何创建一个简单的c++同步锁框架 目录 介绍 背景 临界区 & 互斥 & 信号 临界区 互斥 信号 更多信息 建立锁框架的目的 B ...
- 【转】发布一个基于NGUI编写的UI框架
发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...
随机推荐
- javacpp-FFmpeg系列之3: 像素图像数据转换(BGR与BufferdImage互转,RGB与BufferdImage互转,BufferdImage转Base64编码)
javacpp-ffmpeg系列: javacpp-FFmpeg系列之1:视频拉流解码成YUVJ420P,并保存为jpg图片 javacpp-FFmpeg系列之2:通用拉流解码器,支持视频拉流解码并转 ...
- Data Guard 异构平台支持手册
背景 最简单的DG 环境是同数据库版本,同操作系统平台. 但有时需要在异构平台上来部署DG 环境,比如异构下使用DG 来进行数据迁移,从而降低停机时间和风险等等. 1. 查看主备库的Platform ...
- POJ1006Biorhythms——中国剩余定理
题目:http://poj.org/problem?id=1006 用扩展欧几里得算法求逆元,使用中国剩余定理: 本题较简单,可以手算直接写出,不过我仍使用了模板. 代码如下: #include< ...
- exosip 和 pjsip 简介
oSIP oSIP的开发开始于2000年7月,第一个版本在2001年5月发 布,到现在已经发展到3.x了.它采用ANSI C编写,而且结 构简单小巧,所以速度特别快,它并不提供高层的SIP会话 控制 ...
- Java基础知识之常见关键字(1)
static 特点: 随着类的加载而加载 优先于对象存在 被所有对象所共享 可以直接被类名调用 注意点: 静态方法只能访问静态方法 但是非静态成员可以直接访问静态成员 静态方法中不可以使用this , ...
- H+ Se7en WebUI
http://www.zi-han.net/theme/hplus/webim.html
- 什么是BI(Business Intelligence)
一.BI的定义 BI是Business Intelligence的英文缩写,中文解释为商务智能,用来帮助企业更好地利用数据提高决策质量的技术集合,是从大量的数据中钻取信息与知识的过程.简单讲就是业务. ...
- iview之select选择框选中内容后有空格的问题
导致原因: option组件格式化造成的.此处</Option>在另一行,只要和输出内容一行,就不会有空格了. <Select :label-in-value="true& ...
- Process打开文件
引用:using System.Diagnostics; 打开文件夹: System.Diagnostics.Process.Start(FilePath); 打开文件夹中某个文件: System.D ...
- ASP.NET MVC (Umbraco)中如何设置网站超时自动退出
原文章请参考 https://edgewebware.com/2014/06/automatically-log-out-members-send-login-page-umbraco/ 在网站开发 ...