UIContainerView在事件iOS之后没有响应触摸

时间:2014-10-10 15:40:23

标签: ios objective-c

我正在尝试实现一个抽屉UIContainerView,它允许用户扩展和收缩它以显示信息。我设置了容器视图,“expand”按钮工作正常。

然而,一旦视图“扩展”,它就不再响应触摸。它有一个文本视图和两个按钮。更;当我触摸屏幕时,它会在其后面的collectionView上注册,而不是我应该能够与之交互的按钮。

这是使用容器视图处理父/子关系的代码:

// Parent View Controller.h
{
UIViewController *child1;
profileDescriptionViewController *profileDescription;
}

// Parent View Controller.m
- (void)viewDidLoad
{
    child1 = [self.storyboard instantiateViewControllerWithIdentifier:@"profileDescription"];
[child1 didMoveToParentViewController:self];
}

// Child View Controller.m
- (void)viewDidLoad
{
_profileDescription.text = [[dataHandler getAthlete] profileDescriptionString];
_isExposed = NO;
_frame = self.view.frame;
_height = _frame.size.height;
_yOrigin = _frame.origin.y;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)profileExpand:(id)sender
{
if (_isExposed == NO) {
    [UIView animateWithDuration:0.5 animations:^
     {
         //0, 487, 320, 32
         [self.view setFrame:CGRectMake(_frame.origin.x, _yOrigin - 100, 320, _yOrigin + 150)];

     }
                     completion:^(BOOL finished)
    {
        [self.view setUserInteractionEnabled:YES];
         _isExposed = YES;
     }];
}
/*    else
{
    [UIView animateWithDuration:0.5 animations:^
    {
        [self.view setFrame:CGRectMake(_frame.origin.x, _yOrigin + 100, 320, _yOrigin - 150)];
    }
                     completion:^(BOOL finished)
    {
        _isExposed = NO;
    }];
}*/ 
}

我只是希望视图响应触摸事件。它不会放在parentViewController上的任何UI元素后面,但我无法选择顶部的任何按钮或描述,而是与其后面的元素进行交互。

任何人都有任何想法,为什么会这样?在故事板中,它的设置就像一个常规的容器视图。

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,原因是超级视图不够大,所以在扩展子视图后,你可以看到它,但它没有响应任何触摸事件。您可以将超级视图的clipsToBound设置为NO以进行检查。希望这会有所帮助。