我有一個UIToolbarButton,它有一個UIButton來保存圖像。現在,當我點擊這個UIToolbarButton時,我想在當前視圖中打開另一個視圖。UIToolbarButton上的TapGestureRecognizer不起作用
我的代碼:
- (IBAction)btnNowPlaying:(id)sender
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(openPlaying:)];
[self.view addGestureRecognizer:tap];
}
- (void)openPlaying:(UIGestureRecognizer *)sender
{
NewMainViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Center"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * npvc = [storyboard instantiateViewControllerWithIdentifier:@"NowPlayingVC"];
[vc.containerView addSubview:npvc.view];
}
這個動作,btnNowPlaying是對的UIButton。
爲什麼不直接使用UIBarButton項目的圖像屬性,而不是將UIButton放置在酒吧按鈕內? – trevorj 2014-09-11 05:51:47
如果我使用圖像屬性,圖像未顯示 – 2014-09-11 05:53:39
只顯示色調顏色 – 2014-09-11 05:55:04