如何把一个静态的UIButton覆盖一个UITableView
基本上,我想创build一个静态的UIButton,无论是否滚动表视图。 但是,我试图添加UIButton作为UIView的子视图,并使用“bringSubviewToFront”方法在顶部。 但是,当我滚动UITableView UIButton仍然移动。 因此,我怎样才能使一个静态的UIButton覆盖UITableView?
这是我的代码:
#import "DiscoverTimelineTableViewController.h" @interface DiscoverTimelineTableViewController () @property (strong, nonatomic) UIView* myview; @end @implementation DiscoverTimelineTableViewController - (void)viewDidLoad { [super viewDidLoad]; [self displayMakePlanButton]; NSLog(@"%f", self.view.layer.zPosition); NSLog(@"%f", self.tableView.layer.zPosition); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation. // Return the number of sections. return 1; } - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; // Configure the cell... cell.textLabel.text = @"Sleepy"; return cell; } #pragma mark - Add the make plan button - (void) displayMakePlanButton { CGFloat buttonWidth = self.view.frame.size.width; CGFloat buttonHeight = 104.0f; CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height; CGFloat statBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; UIButton *makePlanButton = [UIButton buttonWithType: UIButtonTypeCustom]; [makePlanButton setFrame:CGRectMake(0, self.view.frame.size.height - buttonHeight - navBarHeight - statBarHeight, buttonWidth, buttonHeight)]; [makePlanButton setBackgroundColor:[UIColor colorWithRed:0.286 green:0.678 blue:0.231 alpha:1]]; [makePlanButton setTitle:@"MAKE PLAN" forState:UIControlStateNormal]; [self.view addSubview:makePlanButton]; //makePlanButton.layer.zPosition = 1; [self.view bringSubviewToFront:makePlanButton]; NSLog(@"%f", makePlanButton.layer.zPosition); } @end
您正在使用表视图控制器,所以self.view是表视图。 表视图是一个滚动视图,所以视图和其他所有内容一起滚动。
您应该使用一个常规的视图控制器与一个表作为子视图。
或者,您可以尝试重置scrollViewDidScroll:
scroll view委托方法中的视图的框架,但我认为该视图仍然会抖动一点。
最后,你可以直接将button添加到UIWindow
,但这可能会带来一系列其他旋转,animation和转换问题。
- 为什么CGPath和UIBezierPath在SpriteKit中定义“顺时针”?
- iOS Storyboard:ViewController之外和场景之上的视图(First Responder和Exit框之间)
- viewDidUnload与viewDidDisappear
- 供应configuration文件,证书,应用程序ID和密钥之间的关系
- NSUserDefaults无法在Swift中使用UITableView
- 如何在后台线程上高效地写入大文件到磁盘(Swift)
- 尝试在iPad上显示后置摄像头时,应用程序会冻结
- 如何从Core Data创build一个CSV文件(swift)
- 后台执行3分钟后自动停止