今是昨非

今是昨非

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

Implementation of Translucent Effects

Implementation of a translucent effect similar to the image below:#

image1.png

Cause:#

While browsing on Tuicool today, I came across an article Writing Protocol-Oriented Views in Swift, which introduces a shaking effect, demonstrating the power of Swift's protocol-oriented programming through direct implementation, category implementation, and protocol extension. I recommend everyone to take a closer look.

At the end of the article, there is a link to Transparent View Controller and Background Mask, which I opened and found a similar translucent implementation as in the first image, but done in Swift.

Then I recalled that there are quite a few requirements for such effects in development, but every time I implement it, I create a custom view and use animation effects. Looking back, this is not only cumbersome but also quite low-quality, isn't it?

Thinking about the implementation above, I wondered how it would be if I translated it into Objective-C. Can it be used? Since Objective-C does not have protocol extensions, I would directly use categories to implement it, which is at least more convenient than rewriting it every time.

Then, here is the result. In DimBackground-OC, it's very simple; you just need to import these two files and use them.
image2.png

However, it is important to note that for the interface to be presented, the Presentation must be set to Over Current Context. The default value is not this; 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.