2010-09-23 2 views
0

У меня проблема с touchsBegan event.I отобразилось изображение в uiimageview.Am пытается обнаружить штрихи на этом изображении, отображая небольшие зеленые точки цвета на изображении, когда я нажал на изображение. Не получаю никаких ошибок во время работы, но это событие затрагивает не firing.Here мой код:TochesBegan не стреляет в xcode?

#import <UIKit/UIKit.h> 
#import "Second.h" 
@interface pickerExampleViewController : UIViewController <UIImagePickerControllerDelegate>{ 
IBOutlet UIButton *selectPic; 

} 
@property (nonatomic,retain) UIButton *selectPic; 
-(IBAction)getpic:(id)sender; 
@end 

#import "pickerExampleViewController.h" 

@implementation pickerExampleViewController 
@synthesize selectPic; 
-(IBAction)getpic:(id)sender 
{ 
UIImagePickerController *picker = [[UIImagePickerController alloc]init]; 
picker.delegate = self; 
picker.editing = YES; 
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
[self presentModalViewController:picker animated:YES]; 
[picker release]; 
} 

#pragma mark imagePickerController delegate methods 
-(void)imagePickerController:(UIImagePickerController *) picker 
    didFinishPickingImage:(UIImage *)image 
    editingInfo:(NSDictionary *)editingInfo 
{ 
[picker dismissModalViewControllerAnimated:YES]; 
Second *secview = [[Second alloc] initWithNibName:@"Second" bundle:nil]; 
secview.view.backgroundColor = [UIColor blackColor]; 
[secview setImage:image]; 
[self.view addSubview:secview.view]; 
//[self presentModalViewController:secview animated:YES]; 
[secview release]; 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
[self dismissModalViewControllerAnimated:YES]; 
} 
@interface Second : UIViewController { 
IBOutlet UIImageView *imgView; 
UIImage *image1; 
} 
@property(nonatomic,retain) UIImageView *imgView; 
-(void)setImage:(UIImage *)img; 
-(IBAction)back; 
@end 
#import "Second.h" 
#import <QuartzCore/QuartzCore.h> 

@implementation Second 
@synthesize imgView; 
static int countoftouches,i; 
CGPoint points[4]; 
-(void)setImage:(UIImage *)img 
{ 
[imgView setImage:img]; 
countoftouches=0; 
} 
-(IBAction)back 
{ 
[self.view removeFromSuperview]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 
//NSSet *allTouches = [event allTouches]; 
if ([touch view] != imgView) { 
    return; 
} 
countoftouches++; 
CGPoint point = [touch locationInView:imgView]; 
NSLog(@"x: %f, y: %f", point.x, point.y); 
CGRect frame=CGRectMake(point.x, point.y, 5, 5); 
if(countoftouches<=4) 
{ 

    points[i] = frame.origin; 
    i++; 
    UIButton *btn=[[UIButton alloc]initWithFrame:frame]; 
    [btn setBackgroundColor:[UIColor greenColor]]; 
    [imgView addSubview:btn]; 
    [btn release]; 
} 

} 
-(void)dealloc 
{ 
[imgView release]; 
[super dealloc]; 
} 
@end 

ответ

1

Вам нужно установить userInteractionEnabled к YES .. на Youre UIImageView, который .. Итак:

imgView.userInteractionEnable = YES; 
+0

я сделал это. Я установил userInteractionEnabled из uiimageview в yes в построителе интерфейса – iphoneStruggler

+0

Я получил его и я d удалить инструкцию [secview release]; в файле pickerExampleViewController.m под pickerdidfinishpicking – iphoneStruggler

Смежные вопросы