2013-01-04 8 views
1

이 이미지 위에 이미지 뷰 및 반투명 버튼이있는 scrollView가 있습니다. 버튼과 이미지 뷰가 [addsubview]로 스크롤 뷰에 추가됩니다. 나는이 버튼 가죽을 한 후스크롤 뷰에서 위치를 변경할 때 UIButton 숨기기

button.frame = CGRectMake(x, y, w, h); 

: 는 지금은 (프레임 속성을 변경)

ES를 이미지 뷰 버튼 위치를 변경해야합니다. 단추 위치 만 변경하면 완벽하게 작동합니다.

추신 : 전 bringtofront를 사용하려고했습니다.

있는 ScrollView 컨텐츠 제작 :

int index = 0; 
    int x = OFFSETXCOPERTINA; 
    int y = 0; 
    int w = LARGHEZZACOPERTINA; 
    int h = ALTEZZACOPERTINA; 
    int riga = 0; 
    int indexriga = 0; 
    int testindex = 0; 

    if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown) { 
     testindex = NRCopertineVerticale; 
    } 
    else { 
     testindex = NRCopertineOrizzontale; 
    } 

    for (NSDictionary *rigaordine in ElencoOrdini) 
    { 

     if (indexriga > 0) x = x + OFFSETXCOPERTINA + w; 
     y = OFFSETYCOPERTINA + (riga * (h + OFFSETYCOPERTINA)); 

     UIButton *buttonCopertina = [UIButton buttonWithType:UIButtonTypeCustom]; 
     buttonCopertina.frame = CGRectMake(x, y, w, h); 

     [buttonCopertina setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(255/255.0) blue:(0/255.0) alpha:0.3]]; 

     UIImage *image = [[UIImage alloc] initWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat: @"%@image.php?CODe=%@", URLXXX, [rigaordine objectForKey:@"cod_isb"]]]]]; 

     UIImageView *copertina = [[UIImageView alloc] initWithImage: image]; 
     [copertina setTag:TAGCopertine + index]; 
     [copertina setFrame:CGRectMake(x, y, w, h)]; 

     [buttonCopertina setTag:TAGButtonCopertine + index]; 
     [buttonCopertina addTarget:self action:@selector(buttonCopertinaClicked:) forControlEvents:UIControlEventTouchUpInside]; 

     [scrollView addSubview:copertina]; 
     [scrollView addSubview:buttonCopertina]; 

     index++; 
     indexriga++; 

     if (indexriga >= testindex) { 
      indexriga = 0; 
      riga++; 
      x = 10; 
     } 

    } 

내가 아이 패드를 회전 할 때 :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    int index = 0; 
    int x = OFFSETXCOPERTINA; 
    int y = 0; 
    int w = LARGHEZZACOPERTINA; 
    int h = ALTEZZACOPERTINA; 
    int riga = 0; 
    int indexriga = 0; 
    int testindex = 0; 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown) { 
     testindex = NRCopertineVerticale; 
    } 
    else { 
     testindex = NRCopertineOrizzontale; 
    } 

    for(int j = 0; j< 999; j++) { 
     if (indexriga > 0) x = x + OFFSETXCOPERTINA + w; 
     y = OFFSETYCOPERTINA + (riga * (h + OFFSETYCOPERTINA)); 

     UIImageView *copertina = (UIImageView *)[self.scrollView viewWithTag:(TAGCopertine + j)]; 
     if (copertina != nil) { 
      copertina.frame = CGRectMake(x, y, LARGHEZZACOPERTINA, ALTEZZACOPERTINA); 
     } 

     UIButton *button = (UIButton *)[self.scrollView viewWithTag:(TAGButtonCopertine + j)]; 
     if (button != nil) { 
      button.frame = CGRectMake(x, y, LARGHEZZACOPERTINA, ALTEZZACOPERTINA); 
     } 

     index++; 
     indexriga++; 

     if (indexriga >= testindex) { 
      indexriga = 0; 
      riga++; 
      x = 10; 
     } 
    } 


} 
+0

코드를 게시 할 수 있습니까? –

+0

UIButton과 UIScrollView의 관계는 무엇입니까? – Stavash

+0

imageView 및 버튼을 추가하면 코드가 어떻게 표시되고 버튼의 프레임도 어떻게 변경됩니까? – TheTiger

답변

0

아마 당신이 버튼의 일부 잘못된 프레임을 설정하는 경우가 오프 스크린 간다. 여기서 올바른 방법은 UIView 하위 클래스를 만들고 그 안에 UIImageViewUIButton을 포함하는 것입니다. 설정 및 이미지 속성을 노출하고 버튼을 터치하기 위해 delegate을 만듭니다. 그런 다음 단추로보기를 인스턴스화하고, 이미지를 설정하고, 대리자를 설정하고 UIScrollView의 하위보기로 추가하고 단추의보기 프레임 만 단추로 변경하면 모든 것이 그에 따라 위치가 변경됩니다.

+0

프레임이 정확합니다. UIImageView 프레임을 변경하지 않으면 단추의 위치가 올바르게 변경됩니다. – MatteoC

+0

나는이 방법을 시도했다. 나는 같은 문제를 겪었다. – MatteoC

0

테스트 한 후에 유일한 방법은 willRotateToInterfaceOrientation에서 UIImageViews의 위치를 ​​변경하는 것입니다.

변경 후 didRotateFromInterfaceOrientation의 UIButtons 위치가 변경됩니다.

설명이있는 것 같지 않지만 작동합니다.

관련 문제