<分区>
<分区>
我想使用 UITouch 移动铅笔图像?我想动动铅笔,它就会写出我们想要的任何内容。
但我无法移动和书写铅笔图像。
非常欢迎专家的任何提示。
最佳答案
以下代码用于在触摸时移动图像
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
关于iphone - 如何使用 UITouch 移动铅笔图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14138948/
相关文章:
ios - swift/Objective-C : How to get value from object by string name
iphone - 在 Objective-C 中将 & 转换为 &
iphone - 将 NSNumber 设置为 NSManagedObject 属性
ios - 如何将 segue doing pop 设置为 root 并在 Storyboard 中推送一个新的?
ios - 快速组合 : `first(_ n: Int)` equivalent to RxSwift `take(_ n: Int)` ?
iphone - 将 NSArray 分隔为 NSString 类型对象的列表
ios - 在带有 Xcode 8 的 Objective C 中使用图表(BarChartDataEntry)iOS 库