我有2個imageviews與它的圖像。我希望當我點擊第一個圖像的圖像應該被選中,如果它被選中它應該返回我的價值TRUE或1應該保存在sqlite數據庫。這是可能的。請問任何人都可以幫助我解決這個問題。 感謝我們如何檢查imageview中的哪個圖像被調用
1
A
回答
0
你去觸摸events.Capture的接觸點,並執行actions.Here我會給UA樣本結構要做到這一點,
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location= [touch locationInView:self.view];
if(CGRectContainsPoint(firstImage.frame, location)) {
//set some flag like
selectionFlag=1; }
else if(CGRectContainsPoint(secImage.frame, location)){
selectionFlag=2; }
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if(CGRectContainsPoint(firstImage.frame, location)) {
if(selectionflag==1) {
//do ur db actions }
}
else if(CGRectContainsPoint(secImage.frame, location)) {
if(selectionflag==2) {
//do ur db actions }
}
selectionflag=0;
}
0
先做
[self.*yourimageViewname* setUserEnteractionEnabled:YES];
BOOL select1,secelect2;
select1=NO;
select2=NO;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
CGPoint touchLocation = [touch locationInView:touch.view];
//give the beginning and ending x and y points in condition to check which imageView is taped
if(touchLocation.x>1 && touchLocation.x<116 && touchLocation.y>133 && touchLocation.y<233)
{
select1=YES;
}
else if(touchLocation.x>120 && touchLocation.x<300 && touchLocation.y>133 && touchLocation.y<233)
{
select2=YES;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
在條件,布爾變量是真的,你可以保存或任何你想做的進一步編碼您的應用程序。
0
1
通過使用UITouch類的方法,你會得到哪個圖像視圖觸摸..或者你可以把imageview裏面的按鈕,然後你會得到點擊事件。
0
你還可以做的是創建兩個按鈕(而不是UIImageViews)有圖像。他們應該顯示大致相同的(你甚至可以禁用觸摸狀態等)。您可以免費獲得UIResponder事件(如在;您可以將操作定位到選擇器)。
更新:這裏大概是如何(雖然沒有打擾配置按鈕)。
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:yourImage forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
// .. now create a second button .. //
,觸碰到你的按鈕將進入下面的方法:
- (void)buttonTouched:(id)sender
{
// .. add your stuff to your database .. //
// .. you can identify your button by sender, or give the button a tag (number) to identify it ../
}
相關問題
- 1. 如何檢查哪個表被調用postgresql中的哪個觸發器?
- 2. solr如何檢查哪個查詢解析器被調用?
- 3. 如何檢查我在C#中調用哪個按鈕?
- 4. 如何檢查ImageView中設置的圖像
- 5. 如何用imageview查找圖像名稱?
- 6. 我們如何檢查對象屬於哪個類?
- 7. 哪個checkbutton已被檢查
- 8. 如何檢查哪個圖像設置爲活動視圖?
- 9. 如何查看哪個圖像是ViewPager中的當前圖像?
- 10. 如何檢查哪個單選按鈕(動態)被檢查?
- 11. 如何檢查哪一個被選中或不使用jQuery
- 12. 檢測哪個圖像與圖像被點擊
- 13. 我如何檢查圖像的類型?
- 14. 我如何檢查imageview是否爲空
- 15. 檢查哪個圖像已設置爲圖像視圖
- 16. 檢索ImageView中的「Clean」圖像
- 17. 如何防止imageview中的圖像被裁剪爲正方形?
- 18. 如何檢查哪個圖像listview包含?
- 19. 在imageView中調用圖像distory生成的圖像
- 20. 如何檢查imageview中的源代碼?
- 21. asterisk命令來檢查哪個DID被調用(星號)
- 22. jquery:我們可以檢測哪個鏈接被點擊從ajaxStart
- 23. firebug - 我如何檢測函數被調用或從哪裏調用函數
- 24. 如何檢查是否一個imageview的有它的圖像,並跳過下一ImageView的
- 25. 調整線條以適應我們的頭像imageview
- 26. 如何從所有圖像檢查寬度和高度已被jquery調用?
- 27. 跟蹤圖像列表中的哪個圖像被點擊?
- 28. 如何查看哪個dll被我的應用程序加載?
- 29. 如何將圖像從一個ImageView截取到另一個ImageView
- 30. 如何更新imageview中的圖像?
您可以使用觸摸方法通過觸摸方法U將得到該圖像視圖觸摸實施這一 – Gypsa 2011-04-27 10:14:34
..並在選擇從圖像視圖獲取圖像並將圖像數據轉儲到文件而不是數據庫。 – santosh 2011-04-27 10:26:13
其實我不能正確得到你可以請你詳細解釋我。謝謝 – Rani 2011-04-27 10:31:06