菜鸟教程小白 发表于 2022-12-12 12:10:29

iOS 7/8 Passcode 屏幕视觉效果


                                            <p><p>想知道是否有人对如何实现此效果有任何见解。特别是数字周围的圆圈,你如何通过圆圈的边缘看到它后面的模糊背景。即使在数字和原始背景之间的图层上出现深色叠加层后,亮度也保持不变。</p>

<p>这是用户尝试解锁 iPhone 时显示的屏幕。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在 iOS 8 中,这可以通过 <a href="https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIVibrancyEffect/index.html" rel="noreferrer noopener nofollow">UIVibrancyEffect</a> 来完成。 :</p>

<pre><code>UIBlurEffect *effect = ;
UIVisualEffectView *viewWithBlurredBackground = [ initWithEffect:effect];
viewWithBlurredBackground.frame = self.view.bounds;

UIVibrancyEffect *vibrancyEffect = ;
UIVisualEffectView *viewWithVibrancy = [ initWithEffect:vibrancyEffect];
viewWithVibrancy.frame = self.view.bounds;

UIButton *button = ;
;
button.layer.cornerRadius = 40;
button.layer.borderWidth = 1.2;
button.layer.borderColor = .CGColor;
button.frame = CGRectMake(100, 100, 80, 80);

;
;
;

NSMutableAttributedString *titleString = [ initWithString:@&#34;2\nA B C&#34;];
range:(NSRange){0, titleString.length}];
range:];
range:];

// Add UILabel on top of the button, in order to avoid UIVibrancyEffect for text.
// If you don&#39;t need it, just call ;

UILabel *notVibrancyLabel = [ init];
notVibrancyLabel.attributedText = titleString;
notVibrancyLabel.textAlignment = NSTextAlignmentCenter;
notVibrancyLabel.numberOfLines = 2;
notVibrancyLabel.frame = button.frame;

;
</code></pre>

<p>还需要在按下按钮时更改背景颜色。</p>

<pre><code>- (void)buttonPressed:(id)sender
{
    UIButton *button = sender;
    // Of course, this is just an example. Better to use subclass for this.
    [UIView animateWithDuration:0.2 animations:^
    {
      button.backgroundColor = ;
    } completion:^(BOOL finished)
    {
      [UIView animateWithDuration:0.2 animations:^
      {
            button.backgroundColor = ;
      }];
    }];
}
</code></pre>

<p>结果:</p>

<p> <img src="/image/86jW0.gif" alt="UIButton with UIVibrancyEffect"/> </p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS 7/8 Passcode 屏幕视觉效果,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26517885/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26517885/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS 7/8 Passcode 屏幕视觉效果