抵消UIRefreshControl

use*_*905 26 ios ios6 uirefreshcontrol

我目前正在为我的应用程序使用JASidePanel,我有一个带UIRefreshControl的UITableViewcontroller作为它的ViewControllers之一.我的tableview的宽度仍然是320像素的宽度,因此UIRefreshControl在视图中间居中.我想弄清楚是否有办法偏移UIRefreshControl(将x向左移动20个像素),这样当我的侧面板可见时它看起来居中.

谢谢! JASidePanel

use*_*202 60

尝试编辑bounds.例如,要将控件向下移动+ 50px:

refreshControl.bounds = CGRectMake(refreshControl.bounds.origin.x,
                                   -50,
                                   refreshControl.bounds.size.width,
                                   refreshControl.bounds.size.height);
[refreshControl beginRefreshing];
[refreshControl endRefreshing];
Run Code Online (Sandbox Code Playgroud)

  • 你也可以使用`refreshControl.bounds = CGRectOffset(refreshControl.bounds,0,50)` (3认同)
  • 我可以确认这个工作,最简单的解决方案 (2认同)
  • 有人可以解释为什么将 -50 设置为 y 原点会将其向下移动 50 点吗? (2认同)

War*_*olf 33

你需要设置框架UIRefreshControl.使用此代码

UIRefreshControl *refContr=[[UIRefreshControl alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[refContr setTintColor:[UIColor blueColor]];
[refContr setBackgroundColor:[UIColor greenColor]];

[stocktable addSubview:refContr];
[refContr setAutoresizingMask:(UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleLeftMargin)];

[[refContr.subviews objectAtIndex:0] setFrame:CGRectMake(30, 0, 20, 30)];


NSLog(@"subViews %@",refContr.subviews); 
Run Code Online (Sandbox Code Playgroud)

输出:
产量

  • UIRefreshControl并不打算作为子视图添加...根据我的经验,当目标没有被删除时这样做会导致崩溃...当添加为子视图时,UIRefreshControl也可能导致其他问题 (3认同)

stu*_*stu 13

我需要这样做才能向下移动UIRefreshControl.我的解决方案是继承UIRefreshControl,并覆盖layoutSubviews方法,在每个子视图上设置CAAffineTransform转换.不幸的是,你不能只在UIRefreshControl上设置转换.

根据需要更改xOffset和yOffset.

@interface MyUIRefreshControl : UIRefreshControl
@end

@implementation MyUIRefreshControl

- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *view in self.subviews) {
        view.transform = CGAffineTransformMakeTranslation(xOffset, yOffset);
    }
}

@end
Run Code Online (Sandbox Code Playgroud)


Ruf*_*rza 8

斯威夫特 5:

有几种方法可以改变 UIRefreshControl 的位置。刷新控件的设置以最方便的方式完成。

刷新控件是滚动视图的一部分的示例:

let refresher = UIRefreshControl()
refresher.addTarget... // Add a proper target.
scrollView.refreshControl = refresher
Run Code Online (Sandbox Code Playgroud)

请注意,您可以使用 tableView 而不是 scrollView。

选项 1:您可以使用视图的框架/边界。

scrollView.refreshControl?.refreshControl.bounds.origin.x = 50
Run Code Online (Sandbox Code Playgroud)

选项 2:或者您可以使用自动布局来完成。


scrollView.refreshControl?.translatesAutoresizingMaskIntoConstraints = false

scrollView.refreshControl?.topAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
scrollView.refreshControl?.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: -50).isActive = true
Run Code Online (Sandbox Code Playgroud)