【问题标题】:UIRefreshControl text overlays on refresh-indicatorUIRefreshControl 文本覆盖在刷新指示器上
【发布时间】:2013-10-03 14:37:34
【问题描述】:

我首先在 XCode 5 下使用 iOS 7 SDK 进行编程。当我使用带有“attributedText”的UIRefreshControl 创建UITableViewController 时,我的文本覆盖在UIRefreshControl 图形之上(圆形进度动画)。

但是当我下拉并松开手指时,文本会跳到正常位置。为什么会这样?

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];

    self.refreshControl = refreshControl;

拉到底前:

UIRefreshControl 发布后:

【问题讨论】:

标签: objective-c overlay ios7 uirefreshcontrol


【解决方案1】:

设置标题后调用layoutIfNeeded

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];
[self.refreshControl layoutIfNeeded];

【讨论】:

    【解决方案2】:

    请试试这个。

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
        refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
        [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
        self.refreshControl = refreshControl;
    
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.refreshControl beginRefreshing];
            [self.refreshControl endRefreshing];
        });
    
    }
    

    【讨论】:

    • 此外,如果您已通过界面生成器添加了刷新控件,只需在您的类中公开您现有的控件,然后使用 dispatch_async ,如本答案所示。这将让您在 IB 中设置变量并减少代码。
    • 有效。假设苹果代码中存在错误,因为我无法想象他们打算使用此解决方案。
    • 苹果还没有解决这个问题!谢谢你的小“黑客”;)
    【解决方案3】:

    将您的代码更改为以下

    self.refreshControl = [UIRefreshControl new];
    [self.refreshControl addTarget:self action:@selector(updateDeviceList) forControlEvents:UIControlEventValueChanged];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Update Devices States"];
    
    self.refreshControl = refreshControl;
    

    这应该可以解决您的问题

    【讨论】:

      猜你喜欢
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 2017-01-22
      相关资源
      最近更新 更多