UINavigation拖动翻页
#import <UIKit/UIKit.h>
#import "ViewController.h" //window窗口
#define WINDOW [[UIApplication sharedApplication]keyWindow] @interface MyNavigationViewController : UINavigationController @end
#define D_screenWidth 568
#define D_leastOffset 50 #import "MyNavigationViewController.h"
#import <QuartzCore/QuartzCore.h> @interface MyNavigationViewController ()
{
CGPoint startTouch;//拖动时的开始坐标
BOOL isMoving;//是否在拖动中
UIView *blackMask;//那层黑面罩 UIImageView *lastScreenShotView;//截图 }
@property (nonatomic,retain) UIView *backgroundView;//背景
@property (nonatomic,retain) NSMutableArray *screenShotsList;//存截图 @end @implementation MyNavigationViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// 只少2个 头一个肯定是顶级的界面
self.screenShotsList = [[NSMutableArray alloc]initWithCapacity:]; }
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
//拖动手势
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];
//添加手势
[self.view addGestureRecognizer:panGesture]; //是否开始拖动
isMoving = NO; } //拖动手势
-(IBAction)handlePanGesture:(UIGestureRecognizer*)sender{ //如果是顶级viewcontroller,结束
if (self.viewControllers.count <= ) return; //得到触摸中在window上拖动的过程中的xy坐标
CGPoint translation=[sender locationInView:WINDOW];
//状态结束,保存数据
if(sender.state == UIGestureRecognizerStateEnded){
NSLog(@"结束%f,%f",translation.x,translation.y);
isMoving = NO; self.backgroundView.hidden = NO;
//如果结束坐标大于开始坐标D_leastOffset像素就动画效果移动
if (translation.x - startTouch.x > D_leastOffset) {
[UIView animateWithDuration:0.3 animations:^{
//动画效果,移动
[self moveViewWithX:D_screenWidth];
} completion:^(BOOL finished) {
//返回上一层
[self popViewControllerAnimated:NO];
//并且还原坐标
CGRect frame = self.view.frame;
frame.origin.x = ;
self.view.frame = frame;
}]; }else{
//不大于D_leastOffset时就移动原位
[UIView animateWithDuration:0.3 animations:^{
//动画效果
[self moveViewWithX:];
} completion:^(BOOL finished) {
//背景隐藏
self.backgroundView.hidden = YES;
}];
}
return; }else if(sender.state == UIGestureRecognizerStateBegan){
NSLog(@"开始%f,%f",translation.x,translation.y);
//开始坐标
startTouch = translation;
//是否开始移动
isMoving = YES;
if (!self.backgroundView)
{
//添加背景
CGRect frame = self.view.frame;
self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(, , frame.size.width , frame.size.height)];
//把backgroundView插入到Window视图上,并below低于self.view层
[WINDOW insertSubview:self.backgroundView belowSubview:self.view]; //在backgroundView添加黑色的面罩
blackMask = [[UIView alloc]initWithFrame:CGRectMake(, , frame.size.width , frame.size.height)];
blackMask.backgroundColor = [UIColor blackColor];
[self.backgroundView addSubview:blackMask];
}
self.backgroundView.hidden = NO; if (lastScreenShotView) [lastScreenShotView removeFromSuperview]; //数组中最后截图
UIImage *lastScreenShot = [self.screenShotsList lastObject];
//并把截图插入到backgroundView上,并黑色的背景下面
lastScreenShotView = [[UIImageView alloc]initWithImage:lastScreenShot];
[self.backgroundView insertSubview:lastScreenShotView belowSubview:blackMask]; } if (isMoving) {
[self moveViewWithX:translation.x - startTouch.x]; }
}
- (void)moveViewWithX:(float)x
{ NSLog(@"Move to:%f",x);
x = x>D_screenWidth?D_screenWidth:x;
x = x<?:x; CGRect frame = self.view.frame;
frame.origin.x = x;
self.view.frame = frame; // float scale = (x/6400)+0.95;//缩放大小
float alpha = 0.4 - (x/(D_screenWidth *));//透明值 //缩放scale
//lastScreenShotView.transform = CGAffineTransformMakeScale(scale, scale);
//背景颜色透明值
blackMask.alpha = alpha; }
//把UIView转化成UIImage,实现截屏
- (UIImage *)ViewRenderImage
{
//创建基于位图的图形上下文 Creates a bitmap-based graphics context with the specified options.:UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale),size大小,opaque是否透明,不透明(YES),scale比例缩放
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); //当前层渲染到上下文
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; //上下文形成图片
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
//结束并删除当前基于位图的图形上下文。
UIGraphicsEndImageContext();
//反回图片
return img;
} #pragma Navagation 覆盖方法
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//图像数组中存放一个当前的界面图像,然后再push
[self.screenShotsList addObject:[self ViewRenderImage]]; [super pushViewController:viewController animated:animated];
} -(UIViewController *)popViewControllerAnimated:(BOOL)animated
{
//移除最后一个
[self.screenShotsList removeLastObject];
return [super popViewControllerAnimated:animated];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UINavigation拖动翻页的更多相关文章
- webapp应用--模拟电子书翻页效果
前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...
- 关于Page翻页效果, PageViewConrtoller
Page View Controllers你使用一个page view controller用page by page的方式来展示内容.一个page view controller管理一个self-c ...
- 页面PC端 / 移动端整屏纵向翻页,点击/触摸滑动效果功能代码非插件
页面翻页,滑动功能示范代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- Android UI【android 仿微信、QQ聊天,带表情,可翻页,带翻页拖动缓冲】
http://blog.csdn.net/lnb333666/article/details/8546497 如题,这是公司项目的一个功能模块,先上个效果图: 其次大致说说原理: 1,首先判断输入的字 ...
- (旧)子数涵数·PS ——翻页效果
一.首先在网络上下载一张图片,作为素材.这是我下载的素材,至于为什么选择这张照片呢,当然不是因为自己的一些羞羞的念头啦. 二.打开Photoshop,我使用的版本是CS3(因为CS3所占的磁盘空间较小 ...
- 6个超炫酷的HTML5电子书翻页动画
相信大家一定遇到过一些电子书网站,我们可以通过像看书一样翻页来浏览电子书的内容.今天我们要分享的HTML5应用跟电子书翻页有关,我们精选出来的6个电子书翻页动画都非常炫酷,而且都提供源码下载,有需要的 ...
- 论坛类应用双Tableview翻页效果实现
作为一名篮球爱好者,经常使用虎扑体育,虎扑体育应用最核心的部分就是其论坛功能,无论哪个版块,论坛都是其核心,而其论坛部分的实现又别具一格,它以两个tableview的形式翻页滚动显示,而不是常见的那种 ...
- 15个最佳jQuery的翻页书效果的例子
在这里,你会发现15的jQuery的翻页书的插件,提供了良好的页面翻转的经验,并帮助创建类似书本的效果. jQuery的增添了一道亮丽的过渡到实际的页面在一本书或杂志HTML5. 1. BookBlo ...
- 利用GPU实现翻页效果
0x00 前言 有一段时间没有更新博客了,在考虑写点什么的时候正好赶上了这个月我的书<Unity 3D脚本编程>又加印了.因此写篇小文聊聊利用shader来实现翻书的效果吧. 虽然本文是这 ...
随机推荐
- 第十一课:js操作选择器的通用函数
1.判断文档是否是XML文档 var isXML = function(elem){ var documentElement = elem && (elem.ownerDocument ...
- 第四次个人作业——关于微软必应词典android客户端的案例分析
[前言] 第一次搞测评这种东西,如果有什么疏漏,请多多谅解.测评内容如题. 第一部分 调研,评测 评测:(设备:Lenovo A806) 软件的bug,功能评测,黑箱测试 bug等级划分方式 5级分类 ...
- SQL基础知识总结(一)
1.union 和union all 操作符 1)union内部的select语句必须拥有相同的列,列也必须有相似的数字类型.同时,每条select语句中列的顺序相同. union语法(结果集无重复) ...
- JAVA成员变量为什么不能在类体中先定义后赋值
package dx; public class Test1 { int a111;//定义成员变量(全局变量) // a = 1;//此处若给变量赋值,会报错,JAVA所有的除定义或声明语句之外的任 ...
- WPF控件--利用Winform库中的NotifyIcon实现托盘小程序
WPF控件--NotifyIcon 运行界面如下所示: 图1 图2 代码很少,如下所示 ...
- Java基础-设计模式之-代理模式Proxy
代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理 ...
- Java 缓存技术
以下仅是对map对方式讨论.没有对点阵图阵讨论.作缓存要做以下2点: 1:清理及更新缓存时机的处理: . 虚拟机内存不足,清理缓存 .. 缓存时间超时,或访问次数超出, 启动线程更新 2:类和方法的 ...
- 【URAL 1917】Titan Ruins: Deadly Accuracy(DP)
题目 #include<cstdio> #include<algorithm> using namespace std; #define N 1005 int n, m, cn ...
- jeecms内容显示条数
1.按照1.2.3.4.5顺序显示 <div class="index-news"> [@cms_channel id='1'] <h2><span& ...
- [NOIP2008] 提高组 洛谷P1006 传纸条
题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是 ...