1

我在故事板中以编程方式显示图像并成功处理横向/纵向方向(请参见下面的代码)。我现在正在尝试通过 Interface Builder 直接在情节提要中的同一视图上添加自定义按钮。应用程序运行时,该按钮不显示。只有图像。你能告诉我在情节提要视图上做这件事的方法吗?或者我也应该以编程方式添加它?还是在 Interface builder 中 100% 重做所有事情?真的不知道如何混合和匹配这两种方法......

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[self navigationController] setNavigationBarHidden:YES animated:YES];



    UIImage *startImage = [UIImage imageNamed:@"title.png"];
    UIImageView *startImageView = [[UIImageView alloc] initWithImage:startImage];

    self.startImageView = startImageView;

    [self.view addSubview:startImageView];


}

- (void) orientStartImageView
{
     UIInterfaceOrientation curOrientation = [UIApplication sharedApplication].statusBarOrientation;
     if (curOrientation == UIInterfaceOrientationPortrait || curOrientation == UIInterfaceOrientationPortraitUpsideDown) {
     [self.startImageView setFrame:CGRectMake(-128, 0, 1024, 1024)];
 }else{
     [self.startImageView setFrame:CGRectMake(0, -128, 1024, 1024)];
 }
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self orientStartImageView];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    [self orientStartImageView];
}
4

1 回答 1

1

它的bcoz您在Button顶部添加ImageView,您可以使用此代码将其置于前面,将其放入viewdidload方法中:

[self.view bringSubviewToFront:yourBtn];
于 2013-02-19T13:03:21.847 回答