1

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ファイルを介して初期化を行い、 (正常に機能した)とs[[[NSBundle mainBundle] loadNibNamed:@"BottomBar" [...]] objectAtIndex:0];を接続しましたが、明らかに同様に機能しませんでした。IBOutletsIBAction

それを解決する方法はありますか?

編集: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いません。どのようにアイデアはありますか?

4

4 に答える 4

0

あなたのコードは

playPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(265.0, 2.0, 40.0, 40.0)];

そのはず

playPauseButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[playPauseButton setFrame:CGRectMake(265.0, 2.0, 40.0, 40.0)];

UIButton Type問題は、コードで必要な を定義していないことです。

于 2013-11-12T20:26:37.010 に答える
0

UIViewControllerが重なり合っていたためUIView、タップを認識できませんでした。

于 2013-11-13T15:16:20.377 に答える