2011-12-11 53 views
0

我想創建一個選項按鈕上方我的滾動視圖,將允許用戶按它,併發生了一些事情。添加UIbutton選項按鈕滾動查看

目前我有一個滾動的地圖,但如果你捏縮放它放大所有包括按鈕..在實際上,我希望按鈕保持原來的大小在原來的位置。

我想我必須爲此發生新的觀點,但如果我這樣做,我將無法控制滾動視圖...所以我想知道如果有人知道我可以如何管理這個?

這裏是我的代碼和什麼一些圖像正在發生

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    //Create Scrollview 
    scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    scrollView.backgroundColor = [UIColor blackColor]; 
    scrollView.delegate = self; 
    scrollView.bounces = NO; 

    //Create Scrolled image 
    backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"auckland-300.jpg"]]; 
    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]]; 

    //Initalize Button Programatically 
    playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [playButton addTarget:self 
        action:@selector(sendHttpsRequest) 
     forControlEvents:UIControlEventTouchDown]; 
    [playButton setTitle:@"Show View" forState:UIControlStateNormal]; 
    playButton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 


    // Note here you should size the container view appropriately and layout backgroundImage and image accordingly. 
    containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,601,601)]; 

    //Add subviews to container 
    [containerView addSubview:backgroundImage]; 
    [containerView addSubview:image]; 

    //Initalize views 
    scrollView.contentSize = containerView.frame.size; 
    [scrollView addSubview:containerView]; 
    [scrollView addSubview:playButton]; 

    //Scrolling 
    scrollView.minimumZoomScale = 0.5; 
    scrollView.maximumZoomScale = 31.0; 
    [scrollView setZoomScale:scrollView.minimumZoomScale]; 
    self.view = scrollView;  


} 

enter image description here

enter image description here

解決方案:

//Initalize views 
    scrollView.contentSize = containerView.frame.size; 
    [scrollView addSubview:containerView]; 

    //Scrolling 
    scrollView.minimumZoomScale = 1.0; 
    scrollView.maximumZoomScale = 31.0; 
    [scrollView setZoomScale:scrollView.minimumZoomScale]; 

    //Set up Highrachys 
    [self.view addSubview:scrollView]; 
    [self.view addSubview:playButton]; 

回答

2

不要設置self.view滾動視圖。相反,將滾動視圖添加爲self.view的子視圖,然後將您的按鈕添加爲self.view的另一個子視圖。

此刻,您的按鈕是滾動視圖的子視圖,因此您所看到的任何滾動操作也適用於該按鈕。該按鈕需要位於視圖層次結構的單獨分支中。

+0

這會影響我的uiscrollview觸摸界面嗎? –

+0

工作!非常感謝.. ..我開始瞭解視圖層次多一點,謝謝一堆! –

+0

如果您添加滾動視圖,然後按鈕,該按鈕將捕獲其框架上的觸摸,但在滾動視圖將採取他們的任何地方。 – jrturton