2012-10-07 2 views
0

.nib 파일의 이미지에 추가 한 버튼을 어떻게 확대 및 축소 할 수 있습니까? 이미지를 확대 할 수 있지만 시뮬레이터의 런타임에는 버튼이 표시되지 않습니다.확대/축소 버튼

나는 줌에 대해 다음 코드를 사용

i do what u say in the view did load and here is the code 
    - (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.visiblePopTipViews = [NSMutableArray array]; 

    self.contents = [NSDictionary dictionaryWithObjectsAndKeys: 
        // Rounded rect buttons 
        @"Play Ground", [NSNumber numberWithInt:1], 
        @"HeadMaster", [NSNumber numberWithInt:2], 
        @"Science Faculty", [NSNumber numberWithInt:3], 
        @"Accounting Faculty", [NSNumber numberWithInt:4], 
        @"Economy Faculty", [NSNumber numberWithInt:5], 
        @"Cultive Faculty", [NSNumber numberWithInt:6], 
        @"Tourisim Faculty", [NSNumber numberWithInt:7], 
        @"Swimming Pool ", [NSNumber numberWithInt:8], 
        @"Medicine Faculty", [NSNumber numberWithInt:9], 
        @"Engeneering Faculty", [NSNumber numberWithInt:10], 
        @"IT Faculty", [NSNumber numberWithInt:11], 
        nil]; 

    // Array of (backgroundColor, textColor) pairs. 
    // NSNull for either means leave as default. 
    // A color scheme will be picked randomly per CMPopTipView. 
    self.colorSchemes = [NSArray arrayWithObjects: 
         [NSArray arrayWithObjects:[NSNull null], [NSNull null], nil], 
         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil], 
         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil], 
         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor darkTextColor], nil], 
         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor blueColor], nil], 
         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil], 
         nil]; 
    scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    scroll.backgroundColor = [UIColor blackColor]; 
    scroll.delegate = self; 

    zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scroll.contentSize.width, scroll.contentSize.height)]; 
    zoomView.backgroundColor = [UIColor whiteColor]; 

    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]]; 
    scroll.contentSize = image.frame.size; 


    UIButton *playGround = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [playGround addTarget:self 
        action:@selector(buttonAction:) 
     forControlEvents:UIControlEventTouchDown]; 
    [playGround setTitle:@"playGround" forState:UIControlStateNormal]; 
    playGround.tag = 1 ; 
    playGround.frame = CGRectMake(290.0, 170.0, 80.0, 40.0); 
    [image addSubview:playGround]; 

    UIButton *masterBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [masterBtn addTarget:self 
        action:@selector(buttonAction:) 
     forControlEvents:UIControlEventTouchDown]; 
    [masterBtn setTitle:@"Presidency" forState:UIControlStateNormal]; 
    masterBtn.tag = 2 ; 
    masterBtn.frame = CGRectMake(250.0, 270.0, 60.0, 30.0); 
    [image addSubview:masterBtn]; 

    UIButton *scienceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [scienceBtn addTarget:self 
        action:@selector(buttonAction:) 
     forControlEvents:UIControlEventTouchDown]; 
    [scienceBtn setTitle:@"science" forState:UIControlStateNormal]; 
    scienceBtn.tag = 3; 
    scienceBtn.frame = CGRectMake(300.0, 330.0, 50.0, 30.0); 
    [image addSubview:scienceBtn]; 

    UIButton *accountingBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [accountingBtn addTarget:self 
         action:@selector(buttonAction:) 
      forControlEvents:UIControlEventTouchDown]; 
    [accountingBtn setTitle:@"Accounting" forState:UIControlStateNormal]; 
    accountingBtn.tag = 4; 
    accountingBtn.frame = CGRectMake(340.0, 360.0, 50.0, 30.0); 
    [image addSubview:accountingBtn]; 

    UIButton *economyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [economyBtn addTarget:self 
        action:@selector(buttonAction:) 
     forControlEvents:UIControlEventTouchDown]; 
    [economyBtn setTitle:@"Economy" forState:UIControlStateNormal]; 
    economyBtn.tag = 5 ; 
    economyBtn.frame = CGRectMake(390.0, 390.0, 50.0, 30.0); 
    [image addSubview:economyBtn]; 

    UIButton *cultiveBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [cultiveBtn addTarget:self 
        action:@selector(buttonAction:) 
     forControlEvents:UIControlEventTouchDown]; 
    [cultiveBtn setTitle:@"Cultive" forState:UIControlStateNormal]; 
    cultiveBtn.tag = 6 ; 
    cultiveBtn.frame = CGRectMake(440.0, 410.0, 50.0, 30.0); 
    [image addSubview:cultiveBtn]; 

    UIButton *tourisimBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [tourisimBtn addTarget:self 
        action:@selector(buttonAction:) 
      forControlEvents:UIControlEventTouchDown]; 
    [tourisimBtn setTitle:@"tourisim" forState:UIControlStateNormal]; 
    tourisimBtn.tag = 7 ; 
    tourisimBtn.frame = CGRectMake(480.0, 440.0, 50.0, 30.0); 
    [image addSubview:tourisimBtn]; 

    UIButton *swimmingBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [swimmingBtn addTarget:self 
        action:@selector(buttonAction:) 
      forControlEvents:UIControlEventTouchDown]; 
    [swimmingBtn setTitle:@"swimming" forState:UIControlStateNormal]; 
    swimmingBtn.tag = 8 ; 
    swimmingBtn.frame = CGRectMake(190.0, 400.0, 50.0, 30.0); 
    [image addSubview:swimmingBtn]; 

    UIButton *medicineBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [medicineBtn addTarget:self 
        action:@selector(buttonAction:) 
      forControlEvents:UIControlEventTouchDown]; 
    [medicineBtn setTitle:@"medicine" forState:UIControlStateNormal]; 
    medicineBtn.tag = 9; 
    medicineBtn.frame = CGRectMake(250.0, 420.0, 70.0, 30.0); 
    [image addSubview:medicineBtn]; 

    UIButton *enegeneeringBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [enegeneeringBtn addTarget:self 
         action:@selector(buttonAction:) 
       forControlEvents:UIControlEventTouchDown]; 
    [enegeneeringBtn setTitle:@"engeneering" forState:UIControlStateNormal]; 
    enegeneeringBtn.tag = 10 ; 
    enegeneeringBtn.frame = CGRectMake(340.0, 460.0, 60.0, 30.0); 
    [image addSubview:enegeneeringBtn]; 

    UIButton *itBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [itBtn addTarget:self 
       action:@selector(buttonAction:) 
    forControlEvents:UIControlEventTouchDown]; 
    [itBtn setTitle:@"It" forState:UIControlStateNormal]; 
    itBtn.tag = 11 ; 
    itBtn.frame = CGRectMake(410.0, 500.0, 60.0, 30.0); 
    [image addSubview:itBtn]; 

    [zoomView addSubview:image ] ; 

    [scroll addSubview:zoomView]; 
    [scroll bringSubviewToFront:zoomView ] ; 
    // [self.view addSubview:scroll ] ; 

    scroll.minimumZoomScale =scroll.frame.size.width/image.frame.size.width; 
    scroll.maximumZoomScale = 2.0; 
    [scroll setZoomScale:scroll.minimumZoomScale]; 
    self.view = scroll; 
    [scroll release]; 
} 


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 
    return image ; 
} 

답변

0

이에는 loadView 방법은 당신의보기 컨트롤러에,있다 없다가? 이 메서드는 View Controller에서 뷰를로드해야 할 때 호출됩니다. nib 파일에 단추를 추가하고이 메서드를 호출하면 단추가 나타나지 않습니다. 코드를로드하는 것이지 펜촉은로드하지 않습니다.

당신이해야 할 일은 하위 뷰로 UIScrollView를 추가하거나 nib 파일에이 중 일부를 추가하는 것입니다. 코드를 작성하는 경우 self.view를 무시하지 말고 자체 뷰에 하위 뷰를 추가하십시오. 이 작업은 loadView 대신 viewDidLoad에서 수행하십시오.

이렇게하면 버튼이 표시됩니다.

+0

나는 이렇게 만들지 만 버튼을 클릭 할 수는 없다. – user1709830

+0

당신은 UIImageView에 UIButtons를 추가하고있다 ...? 그 흥미 롭군요. 당신은 당신이 상상했던 것을 정확하게 쓰지는 않았지만해야 할 일은 ... loadView, viewDidLoad 및 펜촉에서로드하는 방법을 찾아야합니다. 그러면 이러한 것들을 정확하게 쓸 수 있습니다. 그냥 작동 시키려면 버튼을 얻을 수없는 이유는 _inside_ UIImageView인데, 이는 기본적으로 userInteractionEnabled = NO이므로 하위 뷰 (이 경우에는 버튼) 상호 작용할 수 있습니다. image.userInteractionEnabled = YES로 설정하고 어떤 일이 발생하는지 확인하십시오. – cjwirth

+0

그것은 마침내 나와 올바른 코드, 나는 스크롤 [scroll addSubView : 이미지]에 이미지를 추가해야하지만, 나는 버튼을 정의하기 전에 내가 만든이보기에서 thnx 4 힌트를 제거한 뷰를 제거해야한다. 정확히 무엇이 효과가 있었는지 알기 위해 코드에 계속 노력하십시오. – user1709830