我有一个习惯UIView
,我可以在不同地方的整个应用程序中使用它。它基本上看起来像这样:
@interface BottomBar : UIView
{
UIImageView *imageView;
UILabel *nameLabel;
UIButton *playPauseButton;
}
@end
@implementation BottomBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(0.0, 524.0, 320.0, 44.0)];
if (self) {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15.0, 2.0, 40.0, 40.0)];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 2.0, 180.0, 40.0)];
playPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(265.0, 2.0, 40.0, 40.0)];
[self setBackgroundColor:[UIColor colorWithWhite:0.200 alpha:1.000]];
[imageView setImage:[UIImage imageNamed:@"NowPlaying.png"]];
[nameLabel setFont:[UIFont fontWithName:@"Helvetica Neue UltraLight" size:26.0]];
[nameLabel setShadowColor:[UIColor colorWithWhite:0.000 alpha:0.650]];
[nameLabel setShadowOffset:CGSizeMake(1.0, 2.0)];
[playPauseButton setUserInteractionEnabled:YES];
[playPauseButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
[playPauseButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:imageView];
[self addSubview:nameLabel];
[self addSubview:playPauseButton];
}
return self;
}
@end
我剪了一些方法,buttonPressed:(id)sender
方法包括在内,不用担心。但UIButton
不会响应事件或任何事件。它甚至没有突出自己。
我之前通过一个 nib 文件进行了初始化,[[[NSBundle mainBundle] loadNibNamed:@"BottomBar" [...]] objectAtIndex:0];
并连接了IBOutlets
(工作正常)和IBAction
s,这显然不能很好地工作。
任何想法如何解决它?
编辑:我认为它与这部分更相关,因为它似乎UIViewController
是重叠的,尽管它被定义为自由形式并且绝对不重叠。我刚刚测试了它,UIWindow
颜色设置为红色。
无论如何,这是代码:
OverviewViewController *ovc = [[OverviewViewController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:ovc];
[[self window] setRootViewController:nvc];
bottomBar = [[BottomBar alloc] init];
[[self window] addSubview:bottomBar];
[[self window] bringSubviewToFront:bottomBar];
OverviewViewController 在 xib 中定义为 320x460,因此它的底部应该有 44px 用于我的栏。
Edit2:不,调整大小UIViewController
不起作用。有什么想法吗?