3

我拼命想在我的 UICollectionView 上放置一个 UIButton。目标类似于新的foursquare应用程序中的签到按钮。

我的代码目前看起来像这样:

UIButton *floatingButton = [[UIButton alloc] init];
[floatingButton setFrame:CGRectMake(320, 150, 50, 50)];
[floatingButton setBackgroundColor:[UIColor blackColor]];
[self.collectionView addSubview:floatingButton];
[self.collectionView bringSubviewToFront:floatingButton];

问题是按钮不在任何地方。

4

2 回答 2

3

您可能希望将按钮添加到 collectionView 的父视图。最有可能是 self.view,但如果不看更多代码就很难确定。

代替

[self.collectionView addSubview:floatingButton];

你可能想要

[self.view addSubview:floatingButton];
于 2013-05-13T20:54:00.790 回答
2

我有同样的问题。将您的按钮添加到 collectionView superView,可能是 self.view。

[self.view addSubview:floatingButton];

并将按钮设置为 firstResponder。

[floatingButton becomeFirstResponder];
于 2016-02-03T07:22:06.320 回答