Skip to content

Commit

Permalink
lazily create transparent overlay, remove when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Sep 24, 2011
1 parent 35bb907 commit 7563c43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions PSStackedView/PSSVContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ enum {
/// limit to max width
- (CGFloat)limitToMaxWidth:(CGFloat)maxWidth;

/// add rounded masks.
/// currently unused, because this needs offscreen-rendering, which is crazy slow
/// as a workaround, fake te rounded corners yourself
- (void)addMaskToCorners:(UIRectCorner)corners;
- (void)removeMask;

Expand All @@ -40,6 +43,7 @@ enum {
/// set shadow sides
@property(nonatomic, assign) PSSVSide shadow;

/// view controller that is being incapsulated
@property(nonatomic, retain) UIViewController *controller;

/// darken down the view if it's not fully visible
Expand Down
22 changes: 16 additions & 6 deletions PSStackedView/PSSVContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ + (PSSVContainerView *)containerViewWithController:(UIViewController *)controlle

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
transparentView_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
transparentView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
transparentView_.backgroundColor = [UIColor blackColor];
transparentView_.alpha = 0.f;
transparentView_.userInteractionEnabled = NO;
[self addSubview:transparentView_];
}
return self;
}
Expand Down Expand Up @@ -230,7 +224,23 @@ - (void)setShadow:(PSSVSide)shadow {
}

- (void)setDarkRatio:(CGFloat)darkRatio {
BOOL isTransparent = darkRatio > 0.01f;

if (isTransparent && !transparentView_) {
transparentView_ = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.width, self.height)];
transparentView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
transparentView_.backgroundColor = [UIColor blackColor];
transparentView_.alpha = 0.f;
transparentView_.userInteractionEnabled = NO;
[self addSubview:transparentView_];
}

transparentView_.alpha = darkRatio;
if (isTransparent) {
[self addSubview:transparentView_];
}else {
[transparentView_ removeFromSuperview];
}
}

- (CGFloat)darkRatio {
Expand Down

0 comments on commit 7563c43

Please sign in to comment.