2012-03-05 54 views

回答

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   
} 
相關問題