相关疑难解决方法(0)

在UILabel中更改动画文本

I'm setting a new text value to a UILabel. Currently, the new text appears just fine. However, I'd like to add some animation when the new text appears. I'm wondering what I can do to animate the appearance of the new text.

objective-c uilabel ipad caanimation ios

119
推荐指数
8
解决办法
8万
查看次数

我们是否需要在ARC的UIAnimationBlocks中使用__weak self?

我们是否需要在UIAnimation块中使用__weak self,如下所示?如果我们不指定自我弱,是否会产生保留周期问题?

[UIView animateWithDuration:animationDuration 
                      delay:0 
                    options:UIViewAnimationCurveEaseInOut 
                 animations:^{
        [self doSomething];
    } completion:^(BOOL finished) {
        if (finished) {
            [self doSomething];
        }
    }];
Run Code Online (Sandbox Code Playgroud)

我也对以下场景感到困惑.有什么想法吗?请分享您的意见.

[self.navController dismissViewControllerAnimated:animated 
                                       completion:^{
                                                      [self doSomething];
                                                  }];
Run Code Online (Sandbox Code Playgroud)

我们应该在这里使用弱者吗?

ios objective-c-blocks automatic-ref-counting retain-cycle

21
推荐指数
2
解决办法
1万
查看次数

UIView.animate() :我是否需要在动画块中对 self 进行弱引用?

经过一些研究,我发现我的应用程序使用了太多的能量,因为UIView整个应用程序中有几个动画,我在完成块中捕获了相关的动画UIViewController,而没有对其进行弱引用。

所以实际上,我改变了这一点:

func animate() {
    UIView.animate(withDuration: 0.3, animations: {
        self.label.alpha = 0.5
    }) { _ in 
        self.animate()
    }
}
Run Code Online (Sandbox Code Playgroud)

进入这个:

func animate() {
    UIView.animate(withDuration: 0.3, animations: {
        self.label.alpha = 0.5
    }) { [weak self] _ in 
        self?.animate()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我想知道我是否需要对animation块(self.label.alpha = 0.5那个)做同样的事情?

感谢您的帮助

animation uiview ios swift

9
推荐指数
3
解决办法
1万
查看次数

如何使用 dispatchQueues 创建参考循环?

我觉得我一直误解了何时创建引用循环。在我过去认为几乎任何你有一个块并且编译器强迫你写的地方之前,.self这表明我正在创建一个引用循环,我需要使用[weak self] in.

但以下设置不会创建参考循环。

import Foundation
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution


class UsingQueue {
    var property : Int  = 5
    var queue : DispatchQueue? = DispatchQueue(label: "myQueue")

    func enqueue3() {
        print("enqueued")
        queue?.asyncAfter(deadline: .now() + 3) {
            print(self.property)
        }
    }

    deinit {
        print("UsingQueue deinited")
    }
}

var u : UsingQueue? = UsingQueue()
u?.enqueue3()
u = nil
Run Code Online (Sandbox Code Playgroud)

该块仅保留self3 秒。然后释放它。如果我使用async而不是asyncAfter那么它几乎是立即的。

据我了解,这里的设置是:

self ---> queue
self <--- block
Run Code Online (Sandbox Code Playgroud)

队列只是块的外壳/包装器。这就是为什么即使我nil排队,块也会继续执行。他们是独立的。

那么是否有任何设置只使用队列并创建参考循环?

据我所知[weak self],仅用于引用循环以外的其他原因,即 …

closures memory-leaks memory-management grand-central-dispatch swift

5
推荐指数
1
解决办法
1081
查看次数