がサブビューとしてpopviewを追加し、コードは次のとおりです。
//!you must define the dimBackgroundView and set view in head file firstly,
//action for a button,to add set view as a subview
- (IBAction)openSetting:(id)sender {
if(!dimBackgroundView)
{
dimBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
}
dimBackgroundView.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
[self.view addSubview:dimBackgroundView];
SettingViewController *set = [[SettingViewController alloc]initWithNibName:nil bundle:nil];
[set.view setFrame:CGRectMake(120, 50, 400, 600)];
self.setView = set;
//add shadow
set.view.layer.shadowOffset = CGSizeMake(3, 3);
set.view.layer.shadowColor = [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:80.0/255.0 alpha:1.0].CGColor;
set.view.layer.shadowOpacity = 0.8;
[self.view addSubview:set.view];
}
//check touch position, if touch position is outside of setview, remove it from superview
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event{
UITouch *touch = [[event allTouches] anyObject];
if ([self.setView.view superview] && self.dimBackgroundView == touch.view) {
[self.dimBackgroundView removeFromSuperview];
[self.setView.view removeFromSuperview];
}
}
はできません。あなた自身のPopoverControllerを作成する必要があります – nacho4d
ああ!私たち自身のPopoverControllerを作成する方法に関するあらゆる指針?なぜなら、特定の場所でサブビューとして追加するだけでなく、ユーザーがポップオーバーの領域外にタップするときにそれを削除するためです。ありがとう。 –
非常に大きな透明なビューを作成し、その中にポップオーバーを追加します。大きな透明なビューがタッチされると消えます。シンプルですが、見栄えが良くなるには、少しずつ作業(アニメーション、シャドウなど)が必要になります。 – nacho4d