iphone - 如何使用 UITouch 移动铅笔图像?

标签 iphone objective-c ios xcode ipad

<分区>

我想使用 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 - 缩放 MKMapview 以绑定(bind)注释使注释位于 map View 的边缘

下一篇:iphone - 通过发送短信命令远程打开/关闭 Wifi

相关文章:

ios - swift/Objective-C : How to get value from object by string name

ios - 无法使用多个库进行 pod 安装

ios - 代码签名.framework失败,手动包含框架

iphone - 在 Objective-C 中将 & 转换为 &

iphone - 将 NSNumber 设置为 NSManagedObject 属性

ios - 如何将 segue doing pop 设置为 root 并在 Storyboard 中推送一个新的?

ios - 快速组合 : `first(_ n: Int)` equivalent to RxSwift `take(_ n: Int)` ?

iphone - key 扣证书

iphone - 将 NSArray 分隔为 NSString 类型对象的列表

ios - 在带有 Xcode 8 的 Objective C 中使用图表(BarChartDataEntry)iOS 库