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

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)
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)
输出:

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)
斯威夫特 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)
| 归档时间: |
|
| 查看次数: |
21381 次 |
| 最近记录: |