UITabBarController子视图不显示怪异

时间:2016-04-14 23:54:42

标签: objective-c iphone uitabbarcontroller uipickerview

我对使用4标签格式编写的iOS 9 / ObjC应用程序有一个奇怪的问题。 “主”ViewController有几个带控件和图像的子视图。当用户点击图像时,会弹出PickerView,并在图像上再次点击它时将其解除。其他选项卡式ViewControllers可实现简单视图。除了在“主”视图上的单个子视图之外,它都与IB一起放在一起,我在那里将一些Quartz动画绘图叠加在那里的图像视图上。

如果我继续与“主”视图进行交互,则所有操作都完全符合要求。 PickerView按设计出现并消失。标签到另一个ViewController,然后回到“主”视图会导致问题:点击图像视图无法弹出选择器。点击在Quartz图层中被识别,触发Notification事件,该事件在主视图控制器中拾取,然后添加拾取器子视图,将其带到前面并启用交互,就像它正常工作一样,但是即使调试器显示它已成功添加到子视图数组,也不会出现选择器。 更奇怪的是,如果我将主要选项卡切换到任何其他选项卡视图,然后返回主页,则选择器现在会再次出现。这个序列是完全可重复的 - 一旦离开主要标签,选择器不可视化,再次选项卡然后返回主要和选择器工作。

有关从哪里开始寻找的任何想法?感谢

这是一些代码(但我不确定问题出在哪里)

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.picker = [[UIPickerView alloc] init];
    self.picker.datasource = self;
    self.picker.delegate = self;
    float screenWidth = [UIScreen mainScreen].bounds.size.width;
    float pickerWidth = screenWidth * 3 / 4;

    // Calculate the starting x coordinate.
    float xPoint = screenWidth / 2 - pickerWidth / 2;
    [self.Picker setFrame: CGRectMake(xPoint, 50.0f, pickerWidth, 250.0f)];
    [self.Picker setClipsToBounds:NO];
    [self.Picker setBackgroundColor:[UIColor whiteColor]];
    self.Picker.showsSelectionIndicator = YES;
    self.Picker.userInteractionEnabled = YES;
.
.
.
    UIImage *base = [UIImage imageNamed:@"Base"];
    self.baseAView = [[UIImageView alloc] initWithFrame:imFrame];
    [self.baseView setImage:base];
    [self.view addSubview:_baseView];

    self.GView = [[GView alloc] initWithFrame:imFrame];
    self.GView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_GView];
}

-(void) viewDidAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSin) name:@"touchP" object:nil];
}


- (void) doSin {
    // user hits GView, draw Picker if not in View Hierarchy, if in Hierarch, grab value and resign
    NSArray *subViews = [self.view subviews];
    __block NSInteger foundIndex = NSNotFound;
    [subViews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isKindOfClass:[UIPickerView class]]) {
            foundIndex = idx;
            // stop the enumeration
            *stop = YES;
        }
    }];
    if (foundIndex != NSNotFound) {
        // Found the UIPickerView in subviews, so grab value & remove from screen
        [self.view.subviews[foundIndex] removeFromSuperview];
        } else {
        // not in hierarchy, so put it up on screen
        [self.view addSubview:self.Picker];
        [self.view bringSubviewToFront:self.Picker];
        self.view.userInteractionEnabled = YES;
    }
}

0 个答案:

没有答案