0
A
回答
0
使用下列方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
yourPencilImgView.center = [touch locationInView:self];
}
而且
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
yourPencilImgView.center = currentPoint;
}
0
您可以使用UIPanGestureRecognizer
- (void)onDraggingPencil:(UIPanGestureRecognizer *)panGR {
CGPoint translation = [panGR translationInView:baseView];
if (panGR.state == UIGestureRecognizerStateBegan) {
} else if (panGR.state == UIGestureRecognizerStateChanged) {
CGRect _rect = panGR.view.frame;
_rect.origin.x = dragPoint.x + translation.x;
_rect.origin.y = dragPoint.y + translation.y;
panGR.view.frame = _rect;
} else if (panGR.state == UIGestureRecognizerStateEnded) {
}
}
0
下面的代碼是使用了移動圖片上的觸摸
AppDelegate Classes
**// .h File**
#import <UIKit/UIKit.h>
@class UITouchTutorialViewController;
@interface UITouchTutorialAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITouchTutorialViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITouchTutorialViewController *viewController;
@end
//////////////////////////////////////////////////////////////////////////////////
// .m File
#import "UITouchTutorialAppDelegate.h"
#import "UITouchTutorialViewController.h"
@implementation UITouchTutorialAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
//////////////////////////////////////////////////////////////////////////////
UIViewController Classes
// .h file
#import <UIKit/UIKit.h>
@interface UITouchTutorialViewController : UIViewController {
IBOutlet UIImageView *cloud;
}
@end
// .m File
#import "UITouchTutorialViewController.h"
@implementation UITouchTutorialViewController
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
cloud.center = location;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
/*
// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
0
您可以將使用以下代碼下降的圖像
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[imageView_ addGestureRecognizer:panRecognizer];
- (無效)移動:(ID)發送方{
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}
translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];
}
相關問題
- 1. 使用imagemagick將圖像轉換爲鉛筆素描(不是鉛筆素描)
- 2. 繪製圖像,就像一個人正在使用鉛筆
- 3. 用UITouch移動CGRect
- 4. 股利用鉛筆
- 5. Uitouch移動動畫
- 6. 如果客戶搜索「鉛筆」,則不包括「鉛筆刀」
- 7. 用「鉛筆」在畫布上繪圖
- 8. 如何爲iPhone應用程序製作鉛筆筆畫?
- 9. 鉛筆素描在一個活動
- 10. 如何使用iPhone檢測手指移動方向UITouch
- 11. 如何處理圖像的精確UITouch?
- 12. 移動2 CCSprite與UITouch
- 13. 將圖像轉換爲android中的鉛筆素描
- 14. Qt:創建鉛筆/筆刷工具
- 15. 如何移動圖像使用onFling
- 16. 如何使用UIAccelerometer移動圖像?
- 17. 使用Drawline函數創建一個「鉛筆筆劃」
- 18. 如何將位圖轉換爲Android中的鉛筆素描?
- 19. iPhone:如何將照片轉換爲鉛筆圖
- 20. 使用鼠標移動圖像移動
- 21. 用Paint.net鉛筆工具繪製直線
- 22. 使用seekbar移動圖像
- 23. 如何移動圖像
- 24. 如何使圖像平穩移動?
- 25. 如何使圖像陣列移動?
- 26. 如何使圖像頭移動
- 27. 禁用地圖移動從筆觸
- 28. 如何用javascript移動圖像
- 29. 如何用按鈕移動圖像?
- 30. 如何在使用UITouch時獲得觸摸偏移