我正在一個項目中,圖像可拖拽。其中如果我把一個圖像放在另一個圖像上,圖像必須改變。我想要的是 1)我想檢查兩張圖片是否在同一個地方。 2)圖像的位置不能是exact.It可以近似等於如何檢查兩個圖像視圖是否位於同一位置?
2
A
回答
2
這裏有一個方法假設圖像的大小相同
// using ints because it is easier for taking the abs value
int dx,dy;
dx = frame1.origin.x - frame2.origin.x;
dy = frame1.origin.y - frame2.origin.y;
dx = abs(dx);
dy = abs(dy);
// overlapping width and height
int ovHeight, ovWidth;
ovWidth = frame1.size.width-dx;
ovHeight = frame1.size.height-dy;
int ovArea = ovWidth*ovHeight;
int imageArea = frame1.width*frame1.height;
int percentOverlap = ovArea*100/imageArea;
if (percentOverlap > 80) {
// do work here
}
1
CGRect frame1 = imgView1.frame;
CGRect frame2 = imgView2.frame;
這會給你兩個框架structures..which由原點(x的,y)的值和尺寸(寬度,身高) values ..
根據您的需要進行比較。
4
//for checking whether one image is inside another image
if(CGRectContainsRect(ImageView1.frame, ImageView2.frame))
{
//your code for overlapping here
}
//for checking whether one image intersects another
if(CGRectIntersectsRect(ImageView1.frame,ImageView2.frame))
{
//your code for intersection here
}
8
如果要檢查兩個UIImages相交,這是一個好辦法:
CGRect rect1 = myView1.frame;
CGrect rect2 = myView2.frame;
if (CGRectIsNull(CGRectIntersection(rect1, rect2))) {
//They collide
}
你有關於此的所有信息:
相關問題
- 1. 如何檢查一個視圖是否位於另一個視圖之上?
- 2. 如何檢查圖像是否存在於特定位置?
- 3. 兩個圖像在同一位置
- 4. 如何將CSS與兩個圖像對齊,一個位於Upper Rigth位置,另一個位於Down-Right位置?
- 5. Android檢查位圖是否包含另一個位圖
- 6. 檢查兩個位置是否相等
- 7. 同步兩個ScrollView視圖的位置
- 8. 如何檢查位圖圖像是否爲空?
- 9. Android StreetView檢查是否有給定位置的任何視圖
- 10. 如何檢查兩個PictureBox是否具有相同的圖像?
- 11. 檢查一個點是否位於路線中 - Google地圖
- 12. 視圖和視圖模型必須位於相同的位置
- 13. 如何檢查圖像是8位還是16位?
- 14. 如何標記兩個地圖中的兩個不同位置是同一頁?
- 15. 如何檢查圖像視圖中是否存在圖像?
- 16. 圖像視圖 - 是否有可能設置UIImageView dynamicaly的位置?
- 17. 檢查svg元素是否位於視圖框內
- 18. 如何知道是否從位圖圖像視圖或資源
- 19. 如何檢查圖像是否包含在另一個圖像?
- 20. 檢查圖像是否包含鼠標位置
- 21. Visual Basic檢查兩個圖像是否相同或不同
- 22. 無法在一個圖像視圖中設置多個位圖
- 23. 是否有可能在高圖中有兩個Y軸位於高位圖左側,另一個位於右側?
- 24. 定位陣列的兩個實例是否在同一位置
- 25. 如何爲多個圖像視圖設置位圖
- 26. 設置圖像視圖位圖作爲一個返回的位圖
- 27. firefox圖像位置不同於chrome
- 28. 如何檢查兩個對象是否屬於同一個類?
- 29. 檢測兩個圖像在視覺上是否相同
- 30. 隨機圖像的兩個位置相同的一組