在swift3中标签上的UIprogress视图的进度

时间:2017-02-07 13:42:45

标签: xcode swift3 ios10

我正在尝试使用以下代码在标签上显示progressview swift3的进度,但进度停留在10%并且不会继续进行。 请帮助!!!

override func viewDidLoad() {
    super.viewDidLoad()


   Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(myprogressview),userInfo: nil, repeats: true)
}

func myprogressview(timer : Timer)
{

    var count : Int = 0
    count += 1

    if (count <= 10)
    {
        Progress1.progress = Float(count)/10.0
        progressLabel.text = String.init(format: "%d %%", count*10)

    }

    timer.invalidate()
}

1 个答案:

答案 0 :(得分:1)

你必须在else条件下使定时器无效,因为当函数调用第一次定时器无效并且在@Override protected IStatus run(final IProgressMonitor monitor) { monitor.beginTask(....); try { for (;;) { ... do a small amount of work if (monitor.isCanceled()) { ... clean up return Status.CANCEL_STATUS; } } } finally { monitor.done(); } return Status.OK_STATUS; } 函数之外声明计数因为每次它变为零

<LinearLayout android:paddingTop="5dp"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:weightSum="3"
    xmlns:android="http://schemas.android.com/apk/res/android">

        <ImageView
            android:id="@+id/image1"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/logo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <ImageView
            android:id="@+id/image2"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/logo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <ImageView
            android:id="@+id/image3"
            android:layout_weight="1"
            android:src="@drawable/logo"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
</LinearLayout>