当我下拉以刷新UIScrollView时,它需要下拉至屏幕中间

时间:2019-05-09 19:45:45

标签: ios swift xcode uiscrollview refresh

我有一个函数:didPullToRefresh()。为了启用此功能,我必须将UIScrollView一直拉到屏幕中间。是否可以通过仅将屏幕向下拉50个像素来刷新想要刷新的数据?谢谢吗?

这是我当前正在运行的代码:

var refreshControl: UIRefreshControl!
override func viewDidLoad()  {
   super.viewDidLoad()

   scrollView.alwaysBounceVertical = true
   scrollView.bounces  = true
   refreshControl = UIRefreshControl()
   refreshControl.addTarget(self, action: #selector(didPullToRefresh), for: .valueChanged)
   self.scrollView.addSubview(refreshControl)
 }

@objc func didPullToRefresh() {

 print("Refersh")

 // For End refrshing
refreshControl?.endRefreshing()  


 }

1 个答案:

答案 0 :(得分:0)

不要将目标添加到“刷新”控件中。只需将其添加到滚动视图即可。在viewDidLoad中:

#include <jni.h>

/*static google_breakpad::ExceptionHandler *exceptionHandler;
bool callback(const google_breakpad::MinidumpDescriptor &descriptor, 
void *context, bool succeeded) {
    printf("dump path: %s\n", descriptor.path());
    return succeeded;
}*/

extern "C" {
    void Java_org_telegram_messenger_NativeLoader_init(JNIEnv* env, 
    jobject obj, jstring filepath, jboolean enable) {
        return;
        /*if (enable) {
            const char *path = env->GetStringUTFChars(filepath, 0);
            google_breakpad::MinidumpDescriptor descriptor(path);
            exceptionHandler = new google_breakpad::ExceptionHandler(descriptor, NULL, callback, NULL, 
     true, -1);
        }*/
    }
}

将scrollview委托设置为self。并实现以下scrollview委托方法:

scrollView.alwaysBounceVertical = true
scrollView.bounces  = true
scrollView.delegate = self

refreshControl = UIRefreshControl()
self.scrollView.addSubview(refreshControl)

在刷新服务完成后写“ refreshControl?.endRefreshing()”。