- 浏览: 772590 次
- 性别:
- 来自: 天堂
文章分类
最新评论
-
xiaozhao-521:
呀呀呀呀呀呀呀
RequestTest222 -
Andy_hyh:
打扰了,问下openmeeting源码可以运行起来吗?
Openmeetings安装 详细步骤 -
qindongliang1922:
擦,现在还行么,厉害
北京免费吃饭的地方 -
minixx77:
...
Openmeetings安装 详细步骤 -
wwwqqqiang:
喜欢楼主分享问题的方式,有思想
UIView 和 CALayer的那点事
#import <UIKit/UIKit.h>
@interface GesturesViewController : UIViewController {
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UIImageView *imageView;
@end
#import “GesturesViewController.h”
@implementation GesturesViewController
@synthesize imageView;
CGFloat lastScaleFactor = 1;
CGFloat netRotation;
CGPoint netTranslation;
NSArray *images;
int imageIndex = 0;
- (void)viewDidLoad {
//---tap gesture---
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
//---pinch gesture---
UIPinchGestureRecognizer *pinchGesture =[[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePinchGesture:)];
[imageView addGestureRecognizer:pinchGesture];
[pinchGesture release];
//---rotate gesture---
UIRotationGestureRecognizer *rotateGesture =
[[UIRotationGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleRotateGesture:)];
[imageView addGestureRecognizer:rotateGesture];
[rotateGesture release];
//---pan gesture---
UIPanGestureRecognizer *panGesture =
[[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePanGesture:)];
[imageView addGestureRecognizer:panGesture];
[panGesture release];
//---swipe gesture---
images = [[NSArray alloc] initWithObjects:@“architecture.jpg”,
@“Buildings.jpeg”,
@“Bridge.jpeg”, nil];
//---right swipe (default)---
UISwipeGestureRecognizer *swipeGesture =
[[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipeGesture:)];
[imageView addGestureRecognizer:swipeGesture];
[swipeGesture release];
//---left swipe---
UISwipeGestureRecognizer *swipeLeftGesture =
[[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipeGesture:)];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[imageView addGestureRecognizer:swipeLeftGesture];
[swipeLeftGesture release];
//---long press gesture---
UILongPressGestureRecognizer *longpressGesture =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 15;
longpressGesture.numberOfTouchesRequired = 1;
[imageView addGestureRecognizer:longpressGesture];
[longpressGesture release];
[super viewDidLoad];
}
//---handle tap gesture---
-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
if (sender.view.contentMode == UIViewContentModeScaleAspectFit)
sender.view.contentMode = UIViewContentModeCenter;
else
sender.view.contentMode = UIViewContentModeScaleAspectFit;
}
//---handle pinch gesture---
-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
if (factor > 1) {
//---zooming in---
sender.view.transform = CGAffineTransformMakeScale(
lastScaleFactor + (factor-1),
lastScaleFactor + (factor-1));
} else {
//---zooming out---
sender.view.transform = CGAffineTransformMakeScale(
lastScaleFactor * factor,
lastScaleFactor * factor);
}
if (sender.state == UIGestureRecognizerStateEnded){
if (factor > 1) {
lastScaleFactor += (factor-1);
} else {
lastScaleFactor *= factor;
}
}
}
//---handle rotate gesture---
-(IBAction) handleRotateGesture:(UIGestureRecognizer *) sender {
CGFloat rotation = [(UIRotationGestureRecognizer *) sender rotation];
CGAffineTransform transform = CGAffineTransformMakeRotation(
rotation + netRotation);
sender.view.transform = transform;
if (sender.state == UIGestureRecognizerStateEnded){
netRotation += rotation;
}
}
//---handle pan gesture---
-(IBAction) handlePanGesture:(UIGestureRecognizer *) sender {
CGPoint translation = [(UIPanGestureRecognizer *) sender translationInView:imageView];
sender.view.transform = CGAffineTransformMakeTranslation(
netTranslation.x + translation.x,
netTranslation.y + translation.y);
if (sender.state == UIGestureRecognizerStateEnded){
netTranslation.x += translation.x;
netTranslation.y += translation.y;
}
}
//---handle swipe gesture---
-(IBAction) handleSwipeGesture:(UIGestureRecognizer *) sender {
UISwipeGestureRecognizerDirection direction =
[(UISwipeGestureRecognizer *) sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionUp:
NSLog(@“up”);
break;
case UISwipeGestureRecognizerDirectionDown:
NSLog(@“down”);
break;
case UISwipeGestureRecognizerDirectionLeft:
imageIndex++;
break;
case UISwipeGestureRecognizerDirectionRight:
imageIndex--;
break;
default:
break;
}
imageIndex = (imageIndex < 0) ? ([images count] - 1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}
//---handle long press gesture---
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@“Image options”
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@“Save Image”,
@“Copy”, nil];
//---remember to implement the UIActionSheetDelegate protocol in your
// view controller---
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void)dealloc {
[imageView release];
[super dealloc];
}
发表评论
-
iOS 自定义UIActionSheet
2012-12-18 16:07 16418一:模态视图 UIActi ... -
UIView 和 CALayer的那点事
2012-11-17 23:51 30755UIView 和 CALayer的那点事 (1 ... -
iOS Open Source : Popover API for iPhone
2012-01-20 15:02 1941http://iphonedevelopertips.com/ ... -
ios 任务、线程、定时器
2011-12-26 18:09 8028一:operations(任务) cocoa提供了三种 ... -
ios url缓存策略——NSURLCache、 NSURLRequest
2011-12-26 17:09 24357一:url 缓存策略 NSURLRequest ... -
ios NSInvocation简单使用
2011-12-22 16:39 6371在ios直接调用某个对象的消息是方法有两种: 一:perfo ... -
iphone 对Web Services的三种请求方式soap get post
2011-11-09 10:57 6436一:Using SO AP 1.1 POST / ... -
sdk 3.0 手势事件
2011-11-08 17:57 3856一:手势事件类型 1.父类 UIGestureRe ... -
SQLITE3 使用
2011-11-08 16:21 8122一:USING SQLITE3 1.add libsqlit ... -
关于iphone 利用hpple解析html的问题
2011-08-04 18:28 2224最近在用happe解析html中的图片。有个翻页操作,如果请 ... -
iphone hpple 解析html,xml
2011-07-19 16:21 2752使用Objective-C解析HTML或者XML,系统自带有两 ... -
iphone 实现裁剪图片
2011-07-13 09:16 1800方法1: - (void)drawRect:(CGRec ... -
iPhone Open Application Development
2011-06-03 18:19 1036iPhone Open Application Develop ... -
激活 iPhone通过 GPRS 连接服务器功能的代码
2011-05-13 15:14 1657如果您的 iPhone 应用里含有连接服务器的功能,也许会遇到 ... -
address book api 图型
2011-04-28 15:51 1147最近要搞地址簿了,整理一下 -
[OmniGraffle]iPhone app原型制作工具
2011-04-06 17:35 3958在写程序之前,我们通常需要做一些mockup出来(不知道款爷有 ... -
自定义uislider 样式
2011-04-04 21:28 3838UIImage *stetchLeftTrack= [[UII ... -
iphone 下AsyncSocket网络库编程
2011-04-02 21:04 7640iphone的标准推荐CFNetwork ... -
进阶AlertView运用 - 登入设计
2011-04-01 17:52 3038说明:示范如何利用AlertView来制作系统登入的介面程式碼 ... -
iPad UIPopoverController弹出窗口的位置和坐标
2011-04-01 17:42 2000优化规则: TodoViewControlle ...
相关推荐
SDK 2.10.1”、描述“Kinect v2 Examples with MS-SDK 2.10.1”以及标签“unity kinect”,来深入探讨与Kinect v2传感器相关的技术细节及其在Unity开发环境中的应用实例。 ### 一、Kinect v2 介绍 #### 1.1 Kinect...
- **SDK集成**:讲解了如何将Windows CE 6.0 SDK集成到Visual Studio中,以便进行开发工作。 - **项目创建**:详细说明了如何在Visual Studio中创建一个新的Windows CE应用程序项目,并介绍了一些基本的项目设置。 ...
- **应用实例**:手指计数、手势识别等。 ##### 3.22 创建轮廓的边界框和圆 - **边界框**:使用 `boundingRect()` 函数计算轮廓的外接矩形。 - **边界圆**:使用 `minEnclosingCircle()` 函数计算轮廓的外接圆。 - ...
通过MotionEvent对象,可以获取触摸点的位置、压力等信息,这对于实现手势识别等功能非常有用。 **6.4 屏幕间的跳转和事件的传递** 在Android应用中,经常需要从一个Activity跳转到另一个Activity,以实现导航或...