在imageView依次加入7个手势, 1.点击哪个button,往imageView上加入哪个手势.(保证视图上仅仅有一个手势). 2.轻拍:点击视图切换美女图片.(imageView上首先展示的美女
//
// ControlView.h
// HomeworkGestureRecognizer
//
// Created by lanouhn on 14-8-27.
// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.
// #import <UIKit/UIKit.h> @interface ControlView : UIView
@property (nonatomic, retain) NSMutableArray *gestureBtnArr;//存储控制手势切换的按钮
@property (nonatomic, retain) NSMutableArray *animationImages;
@property (nonatomic, retain) NSMutableArray *animationImages1;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIButton *startBtn;//開始播放动画按钮
@property (nonatomic, retain) UIButton *stopBtn;//停止播放动画按钮
@end
//
// ControlView.m
// HomeworkGestureRecognizer
//
// Created by lanouhn on 14-8-27.
// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.
// #import "ControlView.h" @implementation ControlView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.gestureBtnArr = [NSMutableArray array];
[self setupControlBtnView];
[self setupImageView];
[self setupControlAniBtnView];
}
return self;
} - (void)setupControlBtnView
{
CGFloat x = 10;
NSArray *titleArr = @[@"轻拍", @"长按", @"轻扫", @"平移", @"旋转", @"捏合", @"边缘"];
for (int i = 0; i < 7; i++) {
UIButton *gestureBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[gestureBtn setTitle:titleArr[i] forState:UIControlStateNormal];
[gestureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
gestureBtn.layer.cornerRadius = 5;
gestureBtn.frame = CGRectMake(x, 50, 40, 30);
gestureBtn.tag = 100 + i;
gestureBtn.backgroundColor = [UIColor orangeColor];
[self addSubview:gestureBtn];
[self.gestureBtnArr addObject:gestureBtn];
x += 43;
}
} - (void)setupImageView
{
self.animationImages = [NSMutableArray array];
for (int i = 0; i < 22; i++) {
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Zombie%d", i + 1] ofType:@"tiff"]];
[_animationImages addObject:image];
} self.animationImages1 = [NSMutableArray array];
for (int i = 0; i < 18; i++) {
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"SunFlower_%d", i + 1] ofType:@"tiff"]];
[_animationImages1 addObject:image];
} self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"girl_1" ofType:@"jpg"]]];
_imageView.userInteractionEnabled = YES;
_imageView.frame = CGRectMake(40, 100, 240, 368);
_imageView.backgroundColor = [UIColor orangeColor];
// _imageView.animationImages = _animationImages;
_imageView.animationDuration = 1;
[self addSubview:_imageView];
} - (void)setupControlAniBtnView
{
self.startBtn = [UIButton buttonWithType:UIButtonTypeSystem];
_startBtn.backgroundColor = [UIColor orangeColor];
_startBtn.layer.cornerRadius = 5;
_startBtn.frame = CGRectMake(40, 488, 110, 30);
[_startBtn setTitle:@"開始动画" forState:UIControlStateNormal];
[_startBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self addSubview:_startBtn]; self.stopBtn = [UIButton buttonWithType:UIButtonTypeSystem];
_stopBtn.backgroundColor = [UIColor orangeColor];
_stopBtn.layer.cornerRadius = 5;
_stopBtn.frame = CGRectMake(170, 488, 110, 30);
[_stopBtn setTitle:@"结束动画" forState:UIControlStateNormal];
[_stopBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self addSubview:_stopBtn];
} - (void)dealloc
{
self.imageView = nil;
[super dealloc];
} /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/ @end
//
// RootViewController.m
// HomeworkGestureRecognizer
//
// Created by lanouhn on 14-8-27.
// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.
// #import "RootViewController.h"
#import "ControlView.h"
@interface RootViewController ()
{
ControlView *_controlView;
CGFloat _totalRotaion;
}
@end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)loadView
{
_controlView = [[ControlView alloc] init];
_controlView.backgroundColor = [UIColor grayColor];
self.view = _controlView;
[_controlView release]; //给button加入点击事件
for (UIButton *btn in _controlView.gestureBtnArr) {
[btn addTarget:self action:@selector(changeGesture:) forControlEvents:UIControlEventTouchUpInside];
}
[_controlView.startBtn addTarget:self action:@selector(startAni:) forControlEvents:UIControlEventTouchUpInside];
[_controlView.stopBtn addTarget:self action:@selector(stopAni:) forControlEvents:UIControlEventTouchUpInside]; } - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. } - (void)changeGesture:(UIButton *)btn
{
switch (btn.tag) {
case 100:
[self setupTapGesture:btn];
break;
case 101:
[self setupLongPressGesture:btn];
break;
case 102:
[self setupSwipeGesture:btn];
break;
case 103:
[self setupPanGesture:btn];
break;
case 104:
[self setupRotationGesture:btn];
break;
case 105:
[self setupPinchGesture:btn];
break;
case 106:
[self setupScreenEdgePanGesture:btn];
break;
default:
break;
}
} //创建轻拍手势
- (void)setupTapGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[_controlView.imageView addGestureRecognizer:tapGesture];
[tapGesture release];
} //处理轻拍事件
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGesture
{
NSLog(@"%s", __FUNCTION__);
static int i = 2;
_controlView.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"girl_%d", i] ofType:@"jpg"]];
i++;
if (6 == i) {
i = 1;
}
} //创建长按手势
- (void)setupLongPressGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[_controlView.imageView addGestureRecognizer:longPressGesture];
[longPressGesture release];
} //处理长按事件
- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPressGesture
{
UIImageWriteToSavedPhotosAlbum(_controlView.imageView.image, nil, nil, nil);
if (UIGestureRecognizerStateBegan == longPressGesture.state) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"存储图片成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
} //创建轻扫手势
- (void)setupSwipeGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
_controlView.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"boy_1" ofType:@"jpg"]];
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
[_controlView.imageView addGestureRecognizer:swipeGesture];
[swipeGesture release];
} //处理轻扫事件
- (void)handleSwipeGesture:(UISwipeGestureRecognizer *)swipeGesture
{
static int i = 1;
if (swipeGesture.direction == 2) {
i++;
if (6 == i) {
i = 1;
}
_controlView.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"boy_%d", i] ofType:@"jpg"]];
} else if (swipeGesture.direction == 3) {
i--;
if (0 == i) {
i = 5;
}
_controlView.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"boy_%d", i] ofType:@"jpg"]];
}
} //创建平移手势
- (void)setupPanGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[_controlView.imageView addGestureRecognizer:panGesture];
[panGesture release];
} //处理平移事件
- (void)handlePanGesture:(UIPanGestureRecognizer *)panGesture
{
CGPoint point = [panGesture translationInView:panGesture.view];
panGesture.view.transform = CGAffineTransformTranslate(panGesture.view.transform, point.x, point.y);
[panGesture setTranslation:CGPointZero inView:panGesture.view];
} //创建旋转手势
- (void)setupRotationGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationGesture:)];
[_controlView.imageView addGestureRecognizer:rotationGesture];
[rotationGesture release];
} //处理旋转事件
- (void)handleRotationGesture:(UIRotationGestureRecognizer *)rotationGesture
{
rotationGesture.view.transform = CGAffineTransformRotate(rotationGesture.view.transform, rotationGesture.rotation);
NSLog(@"%f", rotationGesture.rotation);
_totalRotaion += rotationGesture.rotation; rotationGesture.rotation = 0;
} //创建捏合手势
- (void)setupPinchGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[_controlView.imageView addGestureRecognizer:pinchGesture];
[pinchGesture release];
} //处理捏合事件
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinchGesture
{
pinchGesture.view.transform = CGAffineTransformScale(pinchGesture.view.transform, pinchGesture.scale, pinchGesture.scale);
pinchGesture.scale = 1.0;
} //创建边缘手势
- (void)setupScreenEdgePanGesture:(UIButton *)btn
{
[self recoverImageView:_controlView.imageView.gestureRecognizers.firstObject];
[self removeGestureRecognizer];
UIScreenEdgePanGestureRecognizer *screenEdgePanGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleScreenEdgePanGesture:)];
screenEdgePanGesture.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:screenEdgePanGesture];
[screenEdgePanGesture release];
} //处理边缘事件
- (void)handleScreenEdgePanGesture:(UIScreenEdgePanGestureRecognizer *)screenEdgePanGesture
{
_controlView.imageView.animationImages = _controlView.animationImages1;
[_controlView.imageView startAnimating];
} //还原视图
- (void)recoverImageView:(UIGestureRecognizer *)gesture
{
if ([gesture respondsToSelector:@selector(setTranslation:inView:)]) {
_controlView.imageView.frame = CGRectMake(40, 100, 240, 368);
} else if ([gesture respondsToSelector:@selector(setRotation:)]) {
UIRotationGestureRecognizer *tempGesture = (UIRotationGestureRecognizer *)gesture;
tempGesture.view.transform = CGAffineTransformRotate(tempGesture.view.transform, -_totalRotaion);
_totalRotaion = 0;
} else if ([gesture respondsToSelector:@selector(setScale:)]) {
_controlView.imageView.frame = CGRectMake(40, 100, 240, 368);
}
self.view.frame = [UIScreen mainScreen].bounds;
} //移除手势
- (void)removeGestureRecognizer
{
for (UIGestureRecognizer *gesture in _controlView.imageView.gestureRecognizers) {
[_controlView.imageView removeGestureRecognizer:gesture];
}
} - (void)startAni:(UIButton *)btn
{
_controlView.imageView.animationImages = _controlView.animationImages;
[_controlView.imageView startAnimating];
} - (void)stopAni:(UIButton *)btn
{
[_controlView.imageView stopAnimating]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// CLAppDelegate.m
// HomeworkGestureRecognizer
//
// Created by lanouhn on 14-8-27.
// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.
// #import "CLAppDelegate.h"
#import "RootViewController.h"
@implementation CLAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RootViewController *rootVC = [[RootViewController alloc] init];
self.window.rootViewController = rootVC;
[rootVC release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} - (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} - (void)dealloc
{
self.window = nil;
[super dealloc];
} @end
在imageView依次加入7个手势, 1.点击哪个button,往imageView上加入哪个手势.(保证视图上仅仅有一个手势). 2.轻拍:点击视图切换美女图片.(imageView上首先展示的美女的更多相关文章
- Scrapy爬取美女图片第三集 代理ip(上) (原创)
首先说一声,让大家久等了.本来打算那天进行更新的,可是一细想,也只有我这样的单身狗还在做科研,大家可能没心思看更新的文章,所以就拖到了今天.不过忙了521,522这一天半,我把数据库也添加进来了,修复 ...
- Scrapy爬取美女图片第四集 突破反爬虫(上)
本周又和大家见面了,首先说一下我最近正在做和将要做的一些事情.(我的新书<Python爬虫开发与项目实战>出版了,大家可以看一下样章) 技术方面的事情:本次端午假期没有休息,正在使用fl ...
- 用python来抓取“煎蛋网”上面的美女图片,尺度很大哦!哈哈
所用Python环境为:python 3.3.2 用到的库为:urllib.request re 废话不多说,先上代码: import urllib.request import re #获 ...
- 使用Python爬虫爬取网络美女图片
代码地址如下:http://www.demodashi.com/demo/13500.html 准备工作 安装python3.6 略 安装requests库(用于请求静态页面) pip install ...
- android高仿抖音、点餐界面、天气项目、自定义view指示、爬取美女图片等源码
Android精选源码 一个爬取美女图片的app Android高仿抖音 android一个可以上拉下滑的Ui效果 android用shape方式实现样式源码 一款Android上的新浪微博第三方轻量 ...
- Python实战:美女图片下载器,海量图片任你下载
Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知识总结.希望大家能够快速入门并学习 ...
- Python爬虫下载美女图片(不同网站不同方法)
声明:以下代码,Python版本3.6完美运行 一.思路介绍 不同的图片网站设有不同的反爬虫机制,根据具体网站采取对应的方法 1. 浏览器浏览分析地址变化规律 2. Python测试类获取网页内容,从 ...
- 强大!HTML5 3D美女图片旋转实现教程
又到周末,来弄点HTML5的特效玩玩,今天要折腾的是HTML5 3D图片特效,图片在垂直方向上被分割成一条条小矩形,在图片上拖动鼠标即可让每一个小矩形旋转,从而让图片形成3D立体的效果,来看看效果图: ...
- python学习(24) 使用Xpath解析并抓取美女图片
Xpath最初用来处理XML解析,同样适用于HTML文档处理.相比正则表达式更方便一些 Xpath基本规则 nodename 表示选取nodename 节点的所有子节点 / 表示当前节点的直接子节点 ...
随机推荐
- ACM算法目录
数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一 ...
- 【Codeforces827D/CF827D】Best Edge Weight(最小生成树性质+倍增/树链剖分+线段树)
题目 Codeforces827D 分析 倍增神题--(感谢T*C神犇给我讲qwq) 这道题需要考虑最小生成树的性质.首先随便求出一棵最小生成树,把树边和非树边分开处理. 首先,对于非树边\((u,v ...
- 如何下载 Nginx (windows 版本)并且简单的使用
官网地址:http://nginx.org/ 进到官网 我这里下载的是 稳定版的 windows版本. 开始我们的简单测试 步骤一:找到nginx的压缩包,(随意找个地方)解压 步骤二:进入conf文 ...
- html5——伸缩比例案例(携程)
1.有图片的盒子,最好是父盒子设置伸缩属性,a标签设置伸缩比例1,img标签宽度100% 2.不要见到父盒子就设置伸缩属性,而是根据子盒子是否占据一行,若是子盒子占据一行,那么只要给子盒子设置伸缩比例 ...
- html——ico
下载: 网址+/favicon.ico 引用: 1.<link href="favicon.ico" rel="icon" /> 2.<lin ...
- Nginx 重新加载日志配置
最近在写一个nginx日志的切割脚本,切割完后,发现可以不重启服务,而直接重新加载日志配置文件的命令 [ kill -USR1 $nginx.pid ],但是不知道 -USR1这个参数是什么意 ...
- 【sqli-labs】 less57 GET -Challenge -Union -14 queries allowed -Variation4 (GET型 挑战 联合查询 只允许14次查询 变化4)
双引号闭合 http://192.168.136.128/sqli-labs-master/Less-57/?id=1"%23 和less56一样查数据
- (转) Arcgis for Javascript实现两个地图的联动
http://blog.csdn.net/gisshixisheng/article/details/40127895 今天在看天地图的时候,有一个多时相的地图显示功能,感觉很好玩,作为技术控的我晚上 ...
- JSON数据 与 JSON数据的使用
https://blog.csdn.net/u010378878/article/details/52943792 https://blog.csdn.net/liuxuan12417/article ...
- Django - 模版语言循环字典
1.可以对传入字典参数做循环显示 views.py中代码: urls.py中代码: html中代码: 在模版语言中,可以对字典进行类似python中的操作(keys,values,items),需要注 ...