1. 程式人生 > >在imageView依次加入7個手勢, 1.點擊哪個button,往imageView上加入哪個手勢.(保證視圖上僅僅有一個手勢). 2.輕拍:點擊視圖切換美女圖片.(imageView上首先展示的美女

在imageView依次加入7個手勢, 1.點擊哪個button,往imageView上加入哪個手勢.(保證視圖上僅僅有一個手勢). 2.輕拍:點擊視圖切換美女圖片.(imageView上首先展示的美女

rac info clas -a 點擊事件 hone sms down dispose

//
//  ControlView.h
//  HomeworkGestureRecognizer
//
//  Created by lanouhn on 14-8-27.
//  Copyright (c) 2014年 [email protected] 陳聰雷. 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年 [email protected]
/* */ 陳聰雷. 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年 [email protected]
/* */ 陳聰雷. 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年 [email protected]
/* */ 陳聰雷. 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上首先展示的美女

相關推薦

imageView依次加入7手勢, 1.哪個button,imageView加入哪個手勢.(保證僅僅一個手勢). 2.:切換美女圖片.(imageView首先展示美女

rac info clas -a 點擊事件 hone sms down dispose // // ControlView.h // HomeworkGestureRecognizer // // Created by lanouhn on 14-8-27. //

用python來抓取“煎蛋網”面的美女圖片,尺度很大哦!哈哈

each file like http add 寫入 header 。。 num 廢話不多說,先上代碼: import urllib.request import re #獲得當前頁面的頁數page_name def get_pagenum(url): req

Linux 7運行級別(0:關機,停機模式、1:單用戶模式、2:多用戶模式、3:完整的多用戶文本模式、4:系統未使用,保留一般不用、5:圖形化模式、6:重啟模式)、重置root密碼方法

oca alt 開機重啟 正常 說明 特殊情況 其中 ice root權限 init是Linux系統操作中不可缺少的程序之一。init進程,它是一個由內核啟動的用戶級進程。內核會在過去曾使用過init的幾個地方查找它,它的正確位置(對Linux系統來說)是/

CAD轉圖片7步驟

cad轉換器 在設計相關行業的朋友們,相信你們對於“cad”這3個字母很熟悉吧。那麽你們有為他煩惱過一陣子嗎?反正小編我提起來簡直是要吐,這家夥真是折磨我夠有段時間的,提他就煩。之後我是在百度上搜索到幾個軟件才得以脫手哩,其中我認為有這麽個軟件幫助我是最多的。特意分享你們——迅捷CAD轉換器,是一

【轉載】【JAVA秒會技術之圖片傳】基於Nginx及FastDFS,完成圖片傳及展示

相互 沒有 con 性能 ext 存儲服務器 網絡 管理 代理配置 基於Nginx及FastDFS,完成商品圖片的上傳及展示 一、傳統圖片存儲及展示方式 存在問題: 1)大並發量上傳訪問圖片時,需要對web應用做負載均衡,但是會存在圖片共享問題 2)web應

掌握這7,讓你的移動端交互體驗更優秀

移動端設計 原型設計 產品經理 以下內容由Mockplus團隊翻譯整理,僅供學習交流,Mockplus是更快更簡單的原型設計工具。 移動端設計的質量好壞,其實並不難度量。當用戶可以流暢輕松地使用,不用耗費精力便可以完成各種任務,這就說明此款APP或者網站的設計足夠優

如何刪除Windows10操作系統資源管理器中的下載、圖片、音樂、文檔、頻、桌面、3D對象這7文件夾

war reg ren 操作系統 esp 桌面 bcf pac cal 通過註冊表刪除,步驟如下: 1、按下win+R,輸入regedit,打開註冊表 2、找到位置:計算機\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr

基於CAS的單登入SSO[4]: 加入CAS客戶端測試單登入

基於CAS的單點登入SSO[4]: 加入兩個CAS客戶端測試單點登入 作者:家輝,日期:2017-08-22 CSDN部落格: http://blog.csdn.net/gobitan 摘要:本系列的前三篇文章分別搭建了基於CAS的單點登入伺服器,並讓伺

Spring Boot 2.1.0 已釋出,7 重大更新!

1、第三方類庫升級 Hibernate 5.3 Micrometer 1.1 Reactor Californium Spring Data Lovelace Spring Framework 5.1 Tomcat 9 Un

Spring Boot 2.1.0 已釋出,7 重大更新你需要了解

Spring Boot 2.1.0 在 10 月底就釋出了,我們來看下 Spring Boot 2.1.0 都更新了什麼,每一個 Java 技術人都值得關注。 棧長其實早就看到了更新了,現在才有時間來更新下。 1、第三方類庫升級 Hibernate 5.3 Micrometer 1.1 Reacto

Spring Boot 2.1.0 已發布,7 重大更新你需要了解

pool for rep ctu err 自動配置 表示 req spring Spring Boot 2.1.0 在 10 月底就發布了,我們來看下 Spring Boot 2.1.0 都更新了什麽,每一個 Java 技術人都值得關註。 棧長其實早就看到了更新了,現在才有

fragment中的ImagView+Text多條目,ImageView二次取樣切換相簿圖片

##Fragmentd的 XML: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android=“http://schemas.and

GitHub7非常值得學習的iOS開源專案

文/小麥麥子(簡書作者) 原文連結:http://www.jianshu.com/p/5cc3dc28bc5e 著作權歸作者所有,轉載請聯絡作者獲得授權,並標註“簡書作者”。 相信從事軟體開發的童鞋應該都有這樣的感觸,不管怎麼學,知識總是學不完的,而且入門一門技術不難,要深入學習一門技術才是真的難。 任何計

安卓imageview實現上面兩圓角下面兩直角的效果

由於產品奇葩要求要求實現下面效果,奇葩的地方就在,要求圖片上面兩個是圓角,下面兩個是直接。自己研究了半天找出來了下面兩種解決方案一,用自定義imageviewimport android.content.Context; import android.graphics.Ca

js中隨機在1~33選7數字,不能重複

//①建立1~33之間的陣列 var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33];//建立一個新陣列,用於儲存找到的7個隨機

7前端不容錯過的jQuery圖片滑塊外掛

作為前端開發者,我們會碰到很到各種各樣的jQuery外掛,但老實說,很少有自己寫的。今天要分享的幾款jQuery圖片滑塊外掛,也就是jQuery焦點圖外掛,基本上會在每個網站都有應用,可以下載看看,也許你可以用到。1、jQuery多圖並列焦點圖外掛今天我們要來分

網易面試題之 牛牛的作業薄上有一個長度為 n 的排列 A,這個排列包含了從1到n的n個數,但是因為一些原因, * 其中一些位置(不超過 10 )看不清了,但是牛牛記得這個數列順序對的數量是 k,

package wangyi; /** * Created by Administrator on 2016/12/7. * 牛牛的作業薄上有一個長度為 n 的排列 A,這個排列包含了從1到n的n個數,但是因為一些原因, * 其中有一些位置(不超過 10 個)看不清