Browse Source

frosted glass view: use toolbar hack only if we can't use UIVisualEffectView

aka on iOS 7

(cherry picked from commit ed3cbef8d54f2f44ff09acf637d1b2ac8e8542a2)
Felix Paul Kühne 9 years ago
parent
commit
bdc16b551a
1 changed files with 20 additions and 7 deletions
  1. 20 7
      Sources/VLCFrostedGlasView.m

+ 20 - 7
Sources/VLCFrostedGlasView.m

@@ -14,13 +14,15 @@
 #import "VLCFrostedGlasView.h"
 
 @interface VLCFrostedGlasView ()
+{
+    BOOL _usingToolbarHack;
+}
 
 #if TARGET_OS_IOS
 @property (nonatomic) UIToolbar *toolbar;
 @property (nonatomic) UIImageView *imageview;
-#else
-@property (nonatomic)  UIVisualEffectView *effectView;
 #endif
+@property (nonatomic)  UIVisualEffectView *effectView;
 
 @end
 
@@ -50,10 +52,19 @@
     [self setClipsToBounds:YES];
 
 #if TARGET_OS_IOS
-    if (![self toolbar]) {
-        [self setToolbar:[[UIToolbar alloc] initWithFrame:[self bounds]]];
-        [self.layer insertSublayer:[self.toolbar layer] atIndex:0];
-        [self.toolbar setBarStyle:UIBarStyleBlack];
+    if ([UIVisualEffectView class] != nil) {
+        _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
+        _effectView.frame = self.bounds;
+        _effectView.clipsToBounds = YES;
+        _effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+        [self insertSubview:_effectView atIndex:0];
+    } else {
+        _usingToolbarHack = YES;
+        if (![self toolbar]) {
+            [self setToolbar:[[UIToolbar alloc] initWithFrame:[self bounds]]];
+            [self.layer insertSublayer:[self.toolbar layer] atIndex:0];
+            [self.toolbar setBarStyle:UIBarStyleBlack];
+        }
     }
 #else
     _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
@@ -67,7 +78,9 @@
 #if TARGET_OS_IOS
 - (void)layoutSubviews {
     [super layoutSubviews];
-    [self.toolbar setFrame:[self bounds]];
+    if (_usingToolbarHack) {
+        [self.toolbar setFrame:[self bounds]];
+    }
 }
 #endif