UIImageView随机消失?

时间:2014-12-07 21:20:51

标签: ios uiimageview ios8-today-widget today-extension

在我的小部件扩展中,我只有以下代码在小部件出现时被调用,代码中没有,我调整_imageView的框架或隐藏属性。但是,每次执行此代码时,代码都能正常运行并完成预期的操作,但_imageView会消失。起初我以为_imageView是以某种方式从视图中删除的,所以我添加了一个日志来注销_imageView的框架,进行检查。日志恢复正常。

然后我发现,如果我要滚动通知中心到窗口小部件不再显示的位置,然后向后滚动,我可以再次看到我的窗口小部件,imageView又回来了,没问题。

执行此代码时,为什么_imageView“消失”?

   if (copiedString && ![textArray containsObject:copiedString]) {

            NSLog(@"String was found, and string hasn't been added before.");

            NSLog(@"Image view frame, is it still there? %@", NSStringFromCGRect(_imageView.frame));

            [textArray addObject:copiedString];

            [defaults setObject:textArray forKey:@"array"];
            [defaults synchronize];

        } else {

            NSLog(@"Nothing interesting here, contents of clipboard: string: %@ image: %@", copiedString, copiedImage);

            NSLog(@"Image view frame, is it still there? %@", NSStringFromCGRect(_imageView.frame));

            [defaults setObject:imageArray forKey:@"imagesArray"];
            [defaults synchronize];

        }

        [_tableView reloadData];

        if (imageArray.count != 0 && self.imageFunctionalityEnabled) {

            if (![defaults boolForKey:@"autoAdd"]) {

                if (textArray.count <= 5) {
                    self.preferredContentSize = CGSizeMake(0, 199 + textArray.count * 43.5);
                } else if (textArray.count >= 5) {
                    self.preferredContentSize = CGSizeMake(0, 199 + 217.5);
                }

            } else {

                if (textArray.count <= 5) {
                    self.preferredContentSize = CGSizeMake(0, 155 + textArray.count * 43.5);
                } else if (textArray.count >= 5) {
                    self.preferredContentSize = CGSizeMake(0, 155 + 217.5);
                }

            }

        } else {

            if (![defaults boolForKey:@"autoAdd"]) {

                if (textArray.count <= 5) {
                    self.preferredContentSize = CGSizeMake(0, 44 + textArray.count * 43.5);
                } else if (textArray.count >= 5) {
                    self.preferredContentSize = CGSizeMake(0, 44 + 217.5);
                }

            } else {

                if (textArray.count <= 5) {
                    self.preferredContentSize = CGSizeMake(0, 0 + textArray.count * 43.5);
                } else if (textArray.count >= 5) {
                    self.preferredContentSize = CGSizeMake(0, 0 + 217.5);
                }

            }

        }

        [defaults setInteger:[UIPasteboard generalPasteboard].changeCount forKey:@"changeCount"];


    }

0 个答案:

没有答案