繁体   English   中英

uiprogressview不会出现在iOS 7中的uitableview下方

[英]uiprogressview doesn't appear below uitableview in iOS 7

我正在编写一个使用UIProgressView的程序,该程序以编程方式添加并在程序执行期间隐藏/显示。 我有以下在iOS 5中可用的代码。该代码通过将UIProgressView添加为UITableView的超级视图的子视图,在UITableView的“下方”添加了UIProgressView。 当UITableView滚动时,这还将UIProgressView保持在一个位置。

在viewDidLoad中,我设置UIProgressView的框架

UIProgressView * progressBar = [[[UIProgressView alloc]    
initWithProgressViewStyle:UIProgressViewStyleBar] retain];
progressBar.hidden = NO;
progressBar.progress = [[NSUserDefaults standardUserDefaults] floatForKey:@"progress"];

//Set up the UIProgressView
frameForProgressBar = CGRectMake(0.0f,
                                 self.tableView.frame.origin.y +      
                                 self.tableView.frame.size.height -  
                                 progressBar.frame.size.height,
                                 self.tableView.frame.size.width,
                                 progressBar.frame.size.height);

progressBar.frame = frameForProgressBar;
insetsForTableView = UIEdgeInsetsMake(0.0, progressBar.frame.size.height, 0.0, 0.0);

然后当我希望UIProgressView出现时

// Add the Progress bar to the Window
progressBarState = ADD_PROGRESS_BAR;
[self.view.superview addSubview:progressBar];

这样我就可以看到UIProgressView,更改UITableView的contentInsets。 为了适应iOS 7,我读到对contentInsets的更改必须在viewWillLayoutSubviews中进行。

-(void) viewWillLayoutSubviews
{
    switch (progressBarState)
    {
        case ADD_PROGRESS_BAR:
            // Set the frame of the UITableView to allow the UIProgressView to appear
            self.tableView.contentInset = insetsForTableView;
            break;
        case REMOVE_PROGRESS_BAR:
            self.tableView.contentInset = UIEdgeInsetsZero;
            break;
        default:
            break;
    }
    progressBarState = UNDEFINED_PROGRESS_BAR;
}

我通过调试器运行此代码,并调用了viewWillLayoutSubviews。 但是,我没有看到UITableView调整大小,也没有看到UIProgressView。 我尝试为UITableView设置框架以使其比屏幕小得多,然后为UIProgressView设置框架,以将其放置在“空”空间中。 但是,我仍然看不到UIP​​rogressView。

有人可以建议为什么我看不到UIP​​rogressView吗?

谢谢,

杰森·马佐塔(Jason Mazzotta)

将UIViewController的AutomaticAdjustsScrollViewInsets属性设置为NO。 由于此属性可用于iOS 7及更高版本,因此请使用responseToSelector方法检查可用性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM