【问题标题】:How to open a child view (customized) on parent view with parent view disabled (not the child view)?如何在禁用父视图(不是子视图)的父视图上打开子视图(自定义)?
【发布时间】:2014-04-30 15:17:03
【问题描述】:

我想通过单击父屏幕上的按钮打开一个屏幕(小屏幕作为子屏幕)。我还想禁用与 父视图 的交互,直到 子视图 打开。我尝试将子视图作为 subview 打开,如果我禁用父视图,它也会禁用有意义的 subview

我还尝试使用 presentViewController子视图 作为单独的视图打开,但在这种情况下,它会完全遮住父屏幕。

打开子视图的最佳方式是什么?以及如何禁用父视图?

解决办法:

ParentViewController 是主视图控制器,而 ChildViewController 是子视图,它只有 .m 和 .h 文件。这样你就可以在自己的类上处理你的点击事件,否则它会抛出异常

在文件 ParentViewController.h 中

#import “ParentViewController.h
#import “ChildViewController.h"
@class ChildViewController;

@interface ParentViewController : UIViewController
{
 ChildViewController *childViewController;
}

在文件 ParentViewController.m 中

 @implementation ParentViewController`
 -(void)viewDidLoad`
 {
  childViewController  = [[ChildViewController alloc]initWithNibName:@“Child” bundle:nil];
 }

  -(IBAction)btnSubView:(id)sender 
  { 
  UIView *clearView = [[UIView alloc]init];
  clearView.frame = self.view.frame;`
  childViewController.view.frame = CGRectMake(200, 350, 404, 227);
  clearView.backgroundColor = [UIColor colorWithRed:0.0 green:0.1 blue:0.4 alpha:0.2];
  [self.view addSubview:clearView];
  [clearView addSubview:groupViewController.view];
  }

【问题讨论】:

    标签: ios objective-c uiview


    【解决方案1】:

    您可以打开一个遮盖父视图的子视图(即,它具有相同的宽度和高度,具有灰色背景,并且消耗触摸),然后在该子视图中打开一个处理您的用户交互的子视图。

    如果你想显示实际的父超级视图,你可以让你的模糊视图透明,你只需要确保在第一层子视图中你捕捉到所有的触摸并且不允许它们被传递给父超级视图。有关信息,请参阅此帖子:how to prevent a touch event passed to a UIView's superview?

    【讨论】:

      【解决方案2】:

      1-创建一个。 xib 并自定义您的 .xib 文件

      2-使用此代码调用子子视图

      CalloutView *calloutView = (CalloutView *)[[[NSBundle mainBundle] loadNibNamed:@"calloutView" owner:self options:nil] objectAtIndex:0];
                  CGRect calloutViewFrame = calloutView.frame;
                  calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
                  calloutView.frame = calloutViewFrame;
      
                  [calloutView.calloutLabel setText:[(locationAnnotation*)[view annotation] title]];
                  [calloutView.CallDattabel setText:[(locationAnnotation*)[view annotation] subtitle]];
                  [calloutView.ImageSate setImage:[(locationAnnotation*)[view annotation] image ]];
                  [view addSubview:calloutView];
      

      【讨论】:

        猜你喜欢
        • 2020-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-11
        • 1970-01-01
        相关资源
        最近更新 更多