今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Implementation of Transparency Effect

Implementation of a Transparency Effect Similar to the Image Below:#

image1.png

Background:#

Today, while browsing on Tuicool, I came across an article Implementing Protocol-Oriented Views in Swift, which introduced a trembling effect. It demonstrated the power of Swift's protocol-oriented approach by implementing it directly, using categories, and through protocol extensions. I recommend everyone to take a closer look.

At the end of the article, there was a link to Transparent View Controllers and Background Masks. I clicked on it and found an implementation similar to the one shown in the first image, but in Swift.

Then, I carefully thought about it. There is a demand for this kind of effect in development, but every time I implemented it, I had to create a custom view and use animation effects. Now, I realize that this approach is not only cumbersome but also outdated.

So, I thought about translating the implementation mentioned above into Objective-C. Can I use it? Since Objective-C does not have protocol extensions, I can directly use categories, which is at least more convenient than rewriting it every time.

Then, here is the result: DimBackground-OC. It's very simple. Just import these two files and use them.
image2.png

However, please note that the view controller that needs to be presented must have its Presentation set to "Over Current Context". By default, it is not set to this value. If not modified, you will find that the final display shows a black background and the underlying interface is not visible.
image3.png

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.