VLCFrostedGlasView.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*****************************************************************************
  2. * VLCFrostedGlasView.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # googlemail.com>
  9. * Felix Paul Kühne <fkuehne # videolan # org>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCFrostedGlasView.h"
  14. @interface VLCFrostedGlasView ()
  15. {
  16. BOOL _usingToolbarHack;
  17. }
  18. #if TARGET_OS_IOS
  19. @property (nonatomic) UIToolbar *toolbar;
  20. @property (nonatomic) UIImageView *imageview;
  21. #endif
  22. @property (nonatomic) UIVisualEffectView *effectView;
  23. @end
  24. @implementation VLCFrostedGlasView
  25. - (id)initWithCoder:(NSCoder *)aDecoder
  26. {
  27. self = [super initWithCoder:aDecoder];
  28. if (self)
  29. [self setupView];
  30. return self;
  31. }
  32. - (instancetype)initWithFrame:(CGRect)frame
  33. {
  34. self = [super initWithFrame:frame];
  35. if (self)
  36. [self setupView];
  37. return self;
  38. }
  39. - (void)setupView
  40. {
  41. [self setClipsToBounds:YES];
  42. #if TARGET_OS_IOS
  43. if (@available(iOS 8, *)) {
  44. _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
  45. _effectView.frame = self.bounds;
  46. _effectView.clipsToBounds = YES;
  47. _effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  48. [self insertSubview:_effectView atIndex:0];
  49. } else {
  50. _usingToolbarHack = YES;
  51. if (![self toolbar]) {
  52. [self setToolbar:[[UIToolbar alloc] initWithFrame:[self bounds]]];
  53. [self.layer insertSublayer:[self.toolbar layer] atIndex:0];
  54. [self.toolbar setBarStyle:UIBarStyleBlack];
  55. }
  56. }
  57. #else
  58. _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
  59. _effectView.frame = self.bounds;
  60. _effectView.clipsToBounds = YES;
  61. _effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  62. [self insertSubview:_effectView atIndex:0];
  63. #endif
  64. }
  65. #if TARGET_OS_IOS
  66. - (void)layoutSubviews {
  67. [super layoutSubviews];
  68. if (_usingToolbarHack) {
  69. [self.toolbar setFrame:[self bounds]];
  70. }
  71. }
  72. #endif
  73. @end