iOS: Place UIView on top of UITableView in fixed position

后端 未结 5 2196
广开言路
广开言路 2020-12-04 13:13

I need to put a UIView (for ads) on top of a UITableView in my iphone app. The problem is that when I scroll the table to the bottom the added UIView is scrolling with the

5条回答
  •  既然无缘
    2020-12-04 13:36

    Here is how it worked for me. The Ad stays at the bottom of the view.

    In ViewDidLoad, in YourController.m:

    awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
    awView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height-kAdWhirlViewHeight/2);
    [self.view addSubview:awView];
    

    Then add this method somewhere in the same .m file:

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGRect newFrame = awView.frame;
        newFrame.origin.x = 0;
        newFrame.origin.y = self.tableView.contentOffset.y+(self.tableView.frame.size.height-kAdWhirlViewHeight);
        awView.frame = newFrame;
    }
    

    Don't forget to declare awView.

提交回复
热议问题