-
Notifications
You must be signed in to change notification settings - Fork 29
add peekView #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add peekView #36
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ - (instancetype)initWithFrame:(CGRect)frame indexTitles:(NSArray *)indexTitles { | |
|
||
-(void)setupWithIndexTitles:(NSArray *)indexTitles { | ||
|
||
_colorPeekView = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1]; | ||
_currentIndex = 0; | ||
_touchStatusViewAlpha = 0.25; | ||
_touchStatusBackgroundColor = [UIColor blackColor]; | ||
|
@@ -314,6 +315,44 @@ - (void)setNewIndexForPoint:(CGPoint)point { | |
break; | ||
} | ||
|
||
if ([self.delegate respondsToSelector:@selector(collectionIndexView:index:)]) { | ||
NSAttributedString * attr = [self.delegate collectionIndexView:self index:self.currentIndex]; | ||
if (attr != NULL) { | ||
UIView * peekView = [self viewWithTag:9999]; | ||
UILabel * titleLabel = [peekView viewWithTag:9998]; | ||
Comment on lines
+321
to
+322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apple has advocated against using Can you update this to use something other than |
||
if(peekView == NULL) { | ||
peekView = [UIView new]; | ||
peekView.layer.cornerRadius = 25; | ||
peekView.layer.backgroundColor = self.colorPeekView.CGColor; | ||
peekView.tag = 9999; | ||
peekView.alpha = 0; | ||
[self addSubview:peekView]; | ||
|
||
titleLabel = [UILabel new]; | ||
titleLabel.tag = 9998; | ||
[peekView addSubview:titleLabel]; | ||
[UIView animateWithDuration:0.3 animations:^{ | ||
peekView.alpha = 1; | ||
}]; | ||
} | ||
|
||
CGFloat maxOffset = self.frame.size.height - 50; | ||
CGFloat minOffset = 0; | ||
CGFloat peekOffset = point.y; | ||
if (peekOffset > maxOffset){ | ||
peekOffset = maxOffset; | ||
} | ||
else if (peekOffset < minOffset) { | ||
peekOffset = minOffset; | ||
} | ||
|
||
peekView.frame = CGRectMake( (self.frame.size.width + 25) * -1, peekOffset, 50, 50); | ||
Comment on lines
+339
to
+349
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No change needed here, but I just want to call this out: I would prefer the offset behavior and size of this peek view be a bit more customizable, but I think this is good for now. I may update this code to add customization options in the future. |
||
titleLabel.frame = peekView.bounds; | ||
titleLabel.attributedText = attr; | ||
titleLabel.textAlignment = NSTextAlignmentCenter; | ||
} | ||
} | ||
|
||
if (newIndex == -1) { | ||
UILabel *topLabel = self.indexLabels[0]; | ||
UILabel *bottomLabel = self.indexLabels[self.indexLabels.count - 1]; | ||
|
@@ -344,6 +383,14 @@ - (void)handleGesture:(UIGestureRecognizer *)recognizer { | |
|
||
if (recognizer != _longPresser) { return; } | ||
if (recognizer.state == UIGestureRecognizerStateEnded) { | ||
|
||
UIView *peekView = [self viewWithTag:9999]; | ||
[UIView animateWithDuration:0.3 animations:^{ | ||
peekView.alpha = 0; | ||
} completion:^(BOOL finished) { | ||
[peekView removeFromSuperview]; | ||
}]; | ||
|
||
if ([self.delegate respondsToSelector:@selector(collectionIndexView:liftedFingerFromIndex:)]) { | ||
[self.delegate collectionIndexView:self liftedFingerFromIndex:self.currentIndex]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> | ||
Comment on lines
+1
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this file from your changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name for this delegate function doesn't tell me anything about what it does. The other two indicate actions a user takes against the index view. What does this one communicate? Can you rename it to something more descriptive, please?