2

の上にフローティングボタンを実装しようとしていますUITableview。そのため、コンテンツがスクロールしてもボタンは同じ位置に留まります。ボタンは透明な画像を保持します。

私はスモークテストを行いましたが、insertSubview:aboveSubview:それぞれに問題なく動作しましたaddSubView

しかし、これをUITableviewof で実行TableViewControllerしてもうまくいかないようです。Button は tableView 上にあり、tableView でスクロールします。興味深いことに、tableView のヘッダーの下にもスクロールします...

これを修正するにはどうすればよいですか - ボタンがテーブルビューの上に浮かんでいますか?

TableViewController.m (作業コード 12.07.2013 で更新)

編集@property (nonatomic) float originalOrigin;TableViewController.hにaを追加

- (void)viewDidLoad
{
    [super viewDidLoad];       
    self.originalOrigin = 424.0;
    [self addOverlayButton];
}


#pragma mark Camera Button 
- (void)addOverlayButton {
    // UIButton *oButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.oButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.oButton.frame = CGRectMake(132.0, self.originalOrigin, 56.0, 56.0);
    self.oButton.backgroundColor = [UIColor clearColor];
    [self.oButton setImage:[UIImage imageNamed:@"CameraButton56x56.png"] forState:UIControlStateNormal];
    [self.oButton addTarget:self action:@selector(toCameraView:) forControlEvents:UIControlEventTouchDown];
    [self.view insertSubview:self.oButton aboveSubview:self.view];
}

// to make the button float over the tableView including tableHeader
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGRect tableBounds = self.tableView.bounds;
    CGRect floatingButtonFrame = self.oButton.frame;
    floatingButtonFrame.origin.y = self.originalOrigin + tableBounds.origin.y;
    self.oButton.frame = floatingButtonFrame;

    [self.view bringSubviewToFront:self.oButton]; // float over the tableHeader
}
4

1 に答える 1