2011-03-07 4 views
0

안녕하세요 저는 iPhone 개발에 익숙하지 않습니다.
버튼 클릭시 프로그래밍 방식으로 UIImageViews를 생성합니다. 버튼을 클릭 할 때마다 같은 위치에서 그려집니다. 이미지 그리기 코드는 다음과 같습니다. UIScrollview에 표시된 이미지를 확인하십시오.

- (IBAction)Button 
{ 
arrayOfImages = [[NSMutableArray alloc]init]; 
float x = 15.0,y = 15.0, width = 100.0, height = 100; 
CGRect frame = CGRectMake(x, y, width, height); 
int i= 0; 

if ([shape isEqualToString:@"Rectangle"]) 
{ 

    UIGraphicsBeginImageContext(frame.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(context, 2.0);  
    CGRect main =CGRectMake(x, y, 70.0, 30.0); 
    CGContextFillRect(context, main); 

    CGRect topSeat1 = CGRectMake(15.0, 0.0, 15.0, 13.0); 
    CGRect topSeat2 = CGRectMake(42.5, 0.0, 15.0, 13.0); 
    CGRect topSeat3 = CGRectMake(70.0, 0.0, 15.0, 13.0); 

    CGRect leftSeat = CGRectMake(0.0, 22.5, 13.0, 15.0); 

    CGRect rightSeat = CGRectMake(87.0, 22.5, 13.0, 15.0); 


    [[UIColor redColor]set]; 
    //UIRectFill(main); 
    UIRectFill(topSeat1); 
    UIRectFill(topSeat2); 
    UIRectFill(topSeat3); 
    UIRectFill(leftSeat); 
    UIRectFill(rightSeat); 
    UIRectFrame(main); 

    [[UIColor blackColor]set]; 
    UIRectFrame(topSeat1); 
    UIRectFrame(topSeat2); 
    UIRectFrame(topSeat3); 
    UIRectFrame(leftSeat); 
    UIRectFrame(rightSeat); 

    UIImage * images = [[UIImage alloc]init]; 
    images = UIGraphicsGetImageFromCurrentImageContext(); 

    UIImageView* myImage=[[UIImageView alloc]initWithFrame:frame]; 
    [myImage setImage:images]; 
    myImage.tag= i; 
    i++; 


    UIGraphicsEndImageContext(); 
    [self.view addSubview:myImage]; 
    [arrayOfImages addObject:myImage]; 
    [myImage setUserInteractionEnabled:YES]; 
} 
} 

내가 원하는 모든

내가 이미 존재하는 경우 UIImageView에 그 자리에서 그려 있는지 확인해야 버튼을 클릭하면 다음 조금 멀리에서있는 UIImageView를 그리는 것입니다.
몇 가지 코드로 도와 주시면 감사하겠습니다.

답변

2

보기의 위치를 ​​조정 한 후, 버튼의 클릭 수를 저장하는 변수를 사용하는 변수를 사용

하거나 파단에 대한 수퍼를 요청하여 이미지로 서브 뷰의 프레임을 비교할 수있다 그는 버튼을 클릭 않으며, 내가 u는 나에게 코드 또는 뭔가 같은 몇 가지 예를 들어 줄 수 runtime.If에서 내 UIImageViews의 위치를 ​​조정할 수있을 것입니다 방법 때 다음 사용자에 따라 달라

for (UIView *subview in self.view.subviews) { 
    if (/* compare subview.frame with myImage.frame */) { 
     /* update myImage.frame */ 
     break; 
    } 
} 
+0

를 볼 수 있습니다. – Hanny

+0

@Hanny : 답변을 수정했습니다. –

관련 문제