2011-12-11 20 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 touchインターフェイスに影響しますか? –

+0

WORKED!私はビューの階層をもう少し理解し始めています、ありがとう、それのためのヒープ! –

+0

スクロールビューを追加した後、ボタンを押すと、フレームのタッチがキャプチャされますが、スクロールビューではそれ以外の場所には表示されません。 – jrturton

関連する問題