2012-10-10 4 views
0

인터페이스 작성기를 사용하지 않고 여러 이미지를 만들었습니다. 내가 가로 모드에서 다른 위치로 이러한 이미지를 이동해야Interface Builder없이 기존 이미지를 이동하는 방법

for (Row* row in parser.rows) { 
     CGRect IphoneFrameImageRect; 
     IphoneFrameImageRect = CGRectMake(10, 10, 150.0f, 150.0f); 
     UIImageView *IphoneFrame = [[UIImageView alloc] initWithFrame:IphoneFrameImageRect]; 
     NSString *IphoneFrameurl = [NSString stringWithFormat:@"http://some.url.com/iphone/IphoneFrame.png"]; 
     [IphoneFrame setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:IphoneFrameurl]]]]; 
     [IphoneFrame setTag:(i)]; 
     IphoneFrame.opaque = YES; // explicitly opaque for performance 

     [self.view addSubview:IphoneFrame]; 
     [IphoneFrame release]; 
} 

:이 코드를 사용했다. 각 이미지에 태그를 추가했는데이 태그를 사용하여 이미지를 다시 선택할 수 있습니다. 하지만 이미지에 새로운 좌표를 부여하려면 어떻게해야합니까? 당신은 다른 두 가지/클래스까지 혼합되어

UIButton *tempButton=(UIButton *)[self.view viewWithTag:i]; 
[temp setFrame:CGRectMake(x, y, X10ButtonWidth, X10ButtonHeight)]; 
+0

UImageView는 tempImage가 아니어야합니까? UIImageView로 변경하면 Button과 마찬가지로 setFrame을 호출 할 수 있습니다. – creativ

답변

0

:이 코드를 사용하여 버튼을 함께 할 수 있어요

-(void)positionViews { 
    UIInterfaceOrientation destOrientation = self.interfaceOrientation; 

    int i=4; //Picture with tag=4 for example 
    UIImage *tempImage=(UIImage *)[self.view viewWithTag:(i)]; 

    // HOW TO MOVE ?? 

} 

:이 코드가

  • UIImage을 그 이미지 표시 데이터가이고 해당 픽셀이 메모리에 있음
  • UIImageView 그 repr 디스플레이 디스플레이에 대한 이미지보기.

그것은 당신에게 더 명확 경우, UIImageNSStringUILabel을 위해 무엇 UIImageView이다. 데이터/컨텐츠를 나타내는 객체는 화면에 표시 할 수있는 뷰와 다릅니다. 당신은 당신이 설정 한 태그를 사용하여 이미지 뷰를 검색하고자 할 때

그래서, 당신은 특히 UIImageViewUIImage하지, 중요한 문제에 대한 보기를 검색 할 수 있습니다.


UIImageView에 캐스트를 변경

당신은 당신의 UIButton 위해 당신이 할 같은 방식으로 setFrame:를 호출 할 수 있습니다 (setFrame:UIView 클래스의 방법이기 때문에, 모두 UIImageViewUIButtonUIView의 서브 클래스).

UIImageView *tempImageView = (UIImageView *)[self.view viewWithTag:(i)]; 
[tempImageView setFrame:...]; 

또는 viewWithTag:UIView를 반환하고 그냥 프레임을 변경하려는 경우 그것은 당신이 필요로하는 모든 것에 따라도, 어떤 캐스트를하지 않는다 : 그것은보기의 UIImageView 또는 어떤 종류의 수행 특히 기본 UIView 또는 여부 속성을 변경하려는 경우 중요하지 않으므로 일반 UIView 클래스의 속성이며 UIView에 적용 할 수 있으며 UIView의 특정 하위 클래스이면 적용 할 수 있습니다.

UIView *tempImageView = [self.view viewWithTag:(i)]; 
[tempImageView setFrame:...]; 
+0

고마워요! 이것은 내가 원하는 방식으로 작동합니다. – ipas

관련 문제