1
我試圖能夠使用觸摸拖動各種圖像。到目前爲止,我試圖讓它只用1張圖片,但它不起作用(即我無法用手指移動圖片)。我究竟做錯了什麼?實現觸摸用手指拖動各種圖像
我有下面的代碼的幾個文件:
DragView.h
@interface DragView : UIImageView {
}
@end
DragView.m
#include "DragView.h"
@implementation DragView
- (void)touchesMoved:(NSSet *)set withEvent:(UIEvent *)event {
CGPoint p = [[set anyObject] locationInView:self.superview];
self.center = p;
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import "DragView.h"
@interface ViewController : UIViewController {
}
@property (nonatomic, strong) DragView *basketView;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize basketView;
- (void)viewDidLoad
{
[super viewDidLoad];
basketView = [[DragView alloc]
initWithImage:[UIImage imageNamed:@"basket.png"]];
basketView.frame = CGRectMake(140, 340.2, 60, 30);
[self.view addSubview:basketView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
工作!感謝您的解釋! – user1824518 2013-03-11 06:44:48