iOS:将 UIView 放在固定位置的 UITableView 之上 [英] iOS: Place UIView on top of UITableView in fixed position

查看:29
本文介绍了iOS:将 UIView 放在固定位置的 UITableView 之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的 iphone 应用程序中的 UITableView 顶部放置一个 UIView(用于广告).问题是,当我将表格滚动到底部时,添加的 UIView 与表格一起滚动.我想要的是将它固定在屏幕底部.有没有办法做到这一点?

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 table. What I want is for it to be fixed on the bottom of the screen. Is there a way to do that?

这是我用来将 UIView 添加到表格的代码:

This is the code which I have used to add the UIView to the table:

 awView = [AdWhirlView requestAdWhirlViewWithDelegate:self]; 
 awView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
 [self.tableView addSubview:awView];

推荐答案

对于像我这样正在寻找使用 Swift 的简单解决方案的人来说,这些答案有点过时了.这是我所做的(假设 myCustomView 是在文件中的其他地方建立的):

For people like me looking for a simple solution using Swift, these answers are kind of outdated. Here's what I did (assuming myCustomView was established somewhere else in the file):

func scrollViewDidScroll(_ scrollView: UIScrollView) {
   
    let pixelsFromBottom = CGFloat(20)//or whatever the
    let theHeight = self.tableView.frame.height + scrollView.contentOffset.y
    myCustomView.frame = CGRect(x: 0, y: theHeight - pixelsFromBottom , width: self.view.frame.width, height: myCustomView.frame.height)

}

这篇关于iOS:将 UIView 放在固定位置的 UITableView 之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆