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来实现翻书的效果吧. 虽然本文是这 ...
随机推荐
- canvas粒子demo
之前在codepen上看到了类似的效果,于是自己也使用coffee-script写了个相似的demo 效果:http://whxaxes.github.io/canvas-test/src/Parti ...
- 自己编写redis客户端[deerlet-redis-client],分享与招募。
引言 最近工作上有需要使用redis,于是便心血来潮打算自己写一个Java客户端.经过两天的努力,目前该客户端已经基本成型.不过可惜的是,由于redis的命令众多,因此LZ还需要慢慢扩展它去支持更多的 ...
- Bootstrap系列 -- 29. 按钮组
单个按钮在Web页面中的运用有时候并不能满足我们的业务需求,常常会看到将多个按钮组合在一起使用,比如富文本编辑器里的一组小图标按钮等 按钮组和下拉菜单组件一样,需要依赖于button.js插件才能正常 ...
- 大型网站系统架构实践(四)http层负载均衡之haproxy实践篇(一)
方案 上篇文章讲到了负载均衡的相关理论知识,这篇文章我打算讲讲实践方法以及实践中遇到的问题 方案:haproxy http层负载均衡 安装一个haproxy服务,两个web服务 haproxy:192 ...
- [c#基础]值类型和引用类型的Equals,==的区别
引言 最近一个朋友正在找工作,他说在笔试题中遇到Equals和==有什么区别的题,当时跟他说如果是值类型的,它们没有区别,如果是引用类型的有区别,但string类型除外.为了证实自己的说法,也研究了一 ...
- java数组的增删改查
import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; p ...
- ios-遍历和排序
// // main.m // OC-遍历和排序-homework // // Created by dllo on 16/2/25. // Copyright © 2016年 dllo. All r ...
- jQuery Mobile学习日记
本次主讲人是王思伦啦啦啦~ 框架特性 jQuery Mobile 以“Write Less, Do More”作为目标,为所有的主流移动操作系统平台提供了高度统一的 UI 框架:jQuery 的移动框 ...
- 转-JS中document对象详解
对象属性 document.title //设置文档标题等价于HTML的<title>标签 document.bgColor //设置页面背景色 document.fgColor //设置 ...
- python 元祖(tuple)
元祖和列表几乎相同,但是元祖一旦初始化是不可变更内容的 元祖的表示方式是caassmates=(), 要记住所有列表能用的.元祖都能用,但是就是不能变内容 注:记住,在python中的元祖,为了引起不 ...