Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Constrict API to using application key window.

  • Loading branch information...
commit e200eef7dc547a8d79ce26f2a64580034cc5a209 1 parent 2b226a5
@modocache authored
View
12 MDCFocusView/MDCFocusView.m
@@ -40,8 +40,9 @@ @implementation MDCFocusView
#pragma mark - Object Initialization
-- (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
+- (id)init {
+ UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
+ self = [super initWithFrame:keyWindow.frame];
if (self) {
_focusDuration = 0.5;
_focalPointViewClass = [MDCFocalPointView class];
@@ -104,9 +105,11 @@ - (void)focus:(UIView *)views, ... {
- (void)focusOnViews:(NSArray *)views {
NSParameterAssert(views != nil);
- [self adjustRotation];
self.focused = YES;
+ [[UIApplication sharedApplication].keyWindow addSubview:self];
+ [self adjustRotation];
+
NSMutableArray *focii = [NSMutableArray arrayWithCapacity:[views count]];
for (UIView *view in views) {
@@ -140,8 +143,9 @@ - (void)dismiss:(void (^)())completion {
self.focii = nil;
self.userInteractionEnabled = NO;
+ [self removeFromSuperview];
+
self.focused = NO;
- [self setNeedsDisplay];
if (completion) {
completion();
View
14 MDCFocusViewTests/MDCFocusViewSpec.m
@@ -34,10 +34,10 @@
describe(@"MDCFocusView", ^{
__block MDCFocusView *focusView = nil;
beforeEach(^{
- focusView = [[MDCFocusView alloc] initWithFrame:CGRectZero];
+ focusView = [MDCFocusView new];
});
- describe(@"-initWithFrame:", ^{
+ describe(@"-init", ^{
it(@"is hidden", ^{
[[theValue(focusView.alpha) should] equal:theValue(0.0f)];
});
@@ -135,16 +135,6 @@
withArguments:theValue(NO)];
[focusView dismiss:nil];
});
-
- context(@"when a completion block is provided", ^{
- it(@"calls the block", ^{
- [[focusView shouldEventually] receive:@selector(removeFromSuperview)];
-
- [focusView dismiss:^{
- [focusView removeFromSuperview];
- }];
- });
- });
});
});
});
View
16 SampleApp/Controllers/SpotlightViewController.m
@@ -58,11 +58,8 @@ - (void)viewDidLoad {
self.bottomButton = [self buildButton:2];
[self.view addSubview:self.bottomButton];
- // First, initialize MDCFocusView using the window's bounds
- UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
- self.focusView = [[MDCFocusView alloc] initWithFrame:keyWindow.frame];
-
- // Customize background
+ // Initialize MDCFocusView and customize its background color
+ self.focusView = [MDCFocusView new];
self.focusView.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f];
// Register a MDCFocalPointView subclass to "wrap" focal points
@@ -70,9 +67,6 @@ - (void)viewDidLoad {
// Add any number of custom views to MDCFocusView
[self.focusView addSubview:[self buildLabel]];
-
- // Finally, add MDCFocusView to window
- [keyWindow addSubview:self.focusView];
}
- (void)viewDidAppear:(BOOL)animated {
@@ -84,11 +78,7 @@ - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.focusView.isFocused) {
- [self.focusView dismiss:^{
- [self.focusView removeFromSuperview];
- }];
- } else {
- [self.focusView removeFromSuperview];
+ [self.focusView dismiss:nil];
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.