Gesture Recognizer code and source files

本文详细介绍如何使用iOS中的各种手势识别器,包括UITapGestureRecognizer、UISwipeGestureRecognizer等,并提供了完整的实现代码。

Gesture Recognizer code and source files
2011-05-09 19:18

Sometimes (like all the time) I forget to actually post some useful code on this blog. Well I was just pondering the epic usefulness of these relatively new Gestures Recognizers you can use in your iPhone or iPad apps, so here’s some code for ya (sample files) or you can read the meat of it below. Use it and you’ll have a…

  • UITapGestureRecognizer (detect taps, either with one or more fingers, and one or more taps)
  • UISwipeGestureRecognizer (detect swipes, either with one or more fingers, swiping Up, Down, Right or Left)
  • UILongPressGestureRecognizer (detects a long press, the example detects a press of 3 seconds)
  • UIPanGestureRecognizer (detects panning)
  • UIRotationGestureRecognizer (detects fingers moving in a rotation)
  • UIPinchGestureRecognizer (detects pinching either inward or outward)

For your header file ( in this case, the file GesturesViewController.h )…

#import <UIKit/UIKit.h>

@interface GesturesViewController : UIViewController <UIGestureRecognizerDelegate> {

UITapGestureRecognizer *tapGR;

UISwipeGestureRecognizer *swipeUpGR;

UILongPressGestureRecognizer *longPressGR;

UIPanGestureRecognizer *panGR;

UIRotationGestureRecognizer *rotationGR;

UIPinchGestureRecognizer *pinchGR;

}

@property (nonatomic, retain) UITapGestureRecognizer *tapGR;

@property (nonatomic, retain) UISwipeGestureRecognizer *swipeUpGR;

@property (nonatomic, retain) UILongPressGestureRecognizer *longPressGR;

@property (nonatomic, retain) UIPanGestureRecognizer *panGR;

@property (nonatomic, retain) UIRotationGestureRecognizer *rotationGR;

@property (nonatomic, retain) UIPinchGestureRecognizer *pinchGR;

@end

For your implementation file ( in this case, the file GesturesViewController.m )

#import “GesturesViewController.h”

@implementation GesturesViewController

@synthesize tapGR, swipeUpGR, longPressGR, panGR, rotationGR, pinchGR;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

[super viewDidLoad];

UIGestureRecognizer *recognizer;

// taps

recognizer = [[ UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];

tapGR = (UITapGestureRecognizer *)recognizer;

tapGR.numberOfTapsRequired = 3;

tapGR.numberOfTouchesRequired = 1;

[self.view addGestureRecognizer:tapGR];

[recognizer release];

//swipe up

recognizer = [[ UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

swipeUpGR = (UISwipeGestureRecognizer *)recognizer;

swipeUpGR.numberOfTouchesRequired = 1;

swipeUpGR.direction = UISwipeGestureRecognizerDirectionUp;  //change Up to Right, Left or down

[self.view addGestureRecognizer:swipeUpGR];

[recognizer release];

// long tap

recognizer = [[ UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];

longPressGR = (UILongPressGestureRecognizer *)recognizer;

longPressGR.minimumPressDuration = 3.0;

[self.view addGestureRecognizer:longPressGR];

[recognizer release];

// pan gr

recognizer = [[ UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

panGR = (UIPanGestureRecognizer *)recognizer;

panGR.minimumNumberOfTouches = 2;

panGR.maximumNumberOfTouches = 6;

[self.view addGestureRecognizer:panGR];

[recognizer release];

// rotation

recognizer = [[ UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotation:)];

rotationGR = (UIRotationGestureRecognizer *)recognizer;

[self.view addGestureRecognizer:rotationGR];

[recognizer release];

// pinch gr

recognizer = [[ UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];

pinchGR = (UIPinchGestureRecognizer *)recognizer;

[self.view addGestureRecognizer:pinchGR];

[recognizer release];

}

-(void) handleTap:(UITapGestureRecognizer *)recognizer  {

NSLog(@”3 taps”);

}

-(void) handleSwipe:(UISwipeGestureRecognizer *)recognizer  {

NSLog(@”Swiped”);

}

-(void) handleLongPress:(UILongPressGestureRecognizer *)recognizer  {

NSLog(@”Long Press”);

}

-(void) handlePan:(UIPanGestureRecognizer *)recognizer  {

NSLog(@”Pan”);

}

-(void) handleRotation:(UIRotationGestureRecognizer *)recognizer  {

/* Get the rotation angle in degrees */

float RotationinDegrees = recognizer.rotation * (180/M_PI);

/* Print it to the debug console */

NSLog(@”%f”, RotationinDegrees);

}

-(void) handlePinch:(UIPinchGestureRecognizer *)recognizer  {

NSLog(@”Pinch”);

}

内容概要:本文档详细介绍了基于直驱永磁同步发电机(PMSG)的1.5MW风力发电系统在Simulink环境下的建模与仿真全过程,涵盖了风力机空气动力学模型、PMSG电磁特性建模、不可控整流与逆变电路、直流环节、空间矢量脉宽调制(SVPWM)技术以及核心控制策略的设计。重点实现了最大功率点跟踪(MPPT)控制以提升风能捕获效率,并构建了电压外环与电流内环协同工作的双闭环控制系统,通过仿真验证了系统在不同风速条件下稳定运行的能力及动态响应性能。; 适合人群:适用于具备电力系统、电机控制理论基础及Simulink仿真操作经验的研究生、科研人员和从事新能源发电系统开发的工程技术人员;特别适合正在进行风电系统建模、控制算法研究或完成相关毕业设计的专业人士。; 使用场景及目标:①深入理解直驱式PMSG风力发电系统的整体架构与工作机理;②掌握从物理部件建模到控制策略实现的完整Simulink仿真流程;③学习并复现MPPT控制、双闭环控制等关键技术方案;④为后续开展低电压穿越、并网稳定性分析、故障诊断等高级课题提供可靠的仿真平台支撑。; 阅读建议:建议结合Matlab/Simulink软件动手实践,逐模块搭建模型,重点关注各控制环节的参数设计与调试方法,同时可参照文中提供的其他风电相关资源进行拓展学习与对比分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值