2012-03-19 75 views
1

我已經在主視圖中以編程方式添加了視圖。在父視圖中,我將程序添加爲子視圖。現在我已經爲clickview設置了touchview的觸摸事件,但它不起作用。點擊時沒有檢測到觸摸事件。我正在使用下面的imageview觸摸事件代碼。將uimageview的觸摸事件添加爲父視圖的子視圖

- (空)的touchesBegan:(NSSet中*)觸及withEvent:方法(的UIEvent *)事件{

UITouch *touch = [touches anyObject]; 

if ([touch view] == originalphoto) 
{ 
    [fullview setHidden:NO]; 
    [self.view addSubview:fullview]; 
    [setimage setImage:image]; 
} 

}

做任何人有想法,如何設置ImageView的觸摸事件,這已以編程方式添加?

非常感謝。

+0

在其中的UIImageView觸摸不工作?它是原始照片嗎?或全景? – Krrish 2012-03-19 11:40:31

回答

1

//添加手勢你的觀點

UITapGestureRecognizer *Tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ResignResponder:)]; 
[tempV addGestureRecognizer:Tap]; 

[Tap release]; 

//method will be called on tapping the view 
-(void)ResignResponder:(UIGestureRecognizer*)recognizer { 
     [LocSearchField resignFirstResponder]; 
     [self.view sendSubviewToBack:tempV]; 
} 
0

也許你需要設置屬性imageView.userInteractionEnabled = YES?

+0

我已經添加了這個屬性,但它不可行。 – Nitin 2012-03-19 11:49:39

1
UITouch *touch = [[event allTouches] anyObject]; 
CGPoint location = [touch locationInView:UIIMAGEVIEW];// uiimageview object 
touchx = location.x; 
touchy = location.y; 
NSLog(@" x= %i ", touchx); 
NSLog(@"y = %i",touchy); 
+0

它沒有檢測到觸摸事件的方法... – Nitin 2012-03-19 11:50:37

+0

這樣做touchBegan mothod它會肯定 – Tornado 2012-03-19 13:01:52

相關問題