Created
June 21, 2013 17:49
-
-
Save armadsen/5832972 to your computer and use it in GitHub Desktop.
Example of how I would do https://code.stypi.com/clifton/Objective-C/reusable.m if I were going to do it essentially the same way. In response to https://twitter.com/cliftonite/status/348133150880317440
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)makeGraphPopup:(NSString *)popupName { | |
/* | |
I want to pass a string (popupName) into this method and use it dynamically | |
for object names just like popupName.to_sym in Ruby. | |
Below you can see where I've insert {popupName} and how it would append itself | |
to various object names which are IBOutlets | |
*/ | |
NSString *responseUrl = [[request URL] absoluteString]; | |
NSArray *urlPieces = [responseUrl componentsSeparatedByString:@"{popupName}://"]; | |
NSString *url = [urlPieces componentsJoinedByString:@""]; | |
//Parse the values coming from the webview URL | |
NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; | |
for (NSString *param in [url componentsSeparatedByString:@"&"]) { | |
NSArray *elts = [param componentsSeparatedByString:@"="]; | |
if([elts count] < 2) continue; | |
[params setObject:[elts objectAtIndex:1] forKey:[elts objectAtIndex:0]]; | |
} | |
NSString *graphPopupKey = [NSString stringWithFormat:@"%@GraphPopup", popupName]; | |
NSString *graphDurationLabelKey = [NSString stringWithFormat:@"%@GraphDurationLabel", popupName]; | |
NSString *graphLabelLabelKey = [NSString stringWithFormat:@"%@GraphLabelLabel", popupName]; | |
NSString *graphPopupArrowKey = [NSString stringWithFormat:@"%@GraphPopupArrow", popupName]; | |
UIView /*I don't know what the type for this actually is*/ *graphPopup = [self valueForKey:graphPopupKey]; | |
UILabel *graphDurationLabel = [self valueForKey:graphDurationLabelKey]; | |
UILabel *graphLabelLabel = [self valueForKey:graphLabelLabelKey]; | |
UIView *graphPopupArrow = [self valueForKey:graphPopupArrowKey]; | |
//Set and show the graph popup | |
graphDurationLabel.text = [params objectForKey:@"hrs"]; | |
graphLabelLabel.text = [params objectForKey:@"date"]; | |
graphPopup.hidden = NO; | |
//Animate into place | |
int currentX = [[params objectForKey:@"xPos"] intValue]; | |
int currentY = [[params objectForKey:@"yPos"] intValue]; | |
if(currentX < 50){ // [-][ ][ ] | |
//Set the left edge of the popup | |
currentX = 0; | |
//Move the pointer arrow on the popup | |
CGRect popupFrame = graphPopupArrow.frame; | |
popupFrame.origin.x = 22; | |
graphPopupArrow.frame = popupFrame; | |
}else if(currentX > 214){ // [ ][ ][-] | |
//Set the left edge of the popup | |
currentX = 214; | |
//Move the pointer arrow on the popup | |
CGRect popupFrame = graphPopupArrow.frame; | |
popupFrame.origin.x = 68; | |
graphPopupArrow.frame = popupFrame; | |
}else{ // [ ][-][ ] | |
//Set the left edge of the popup | |
currentX -= 42; | |
//Move the pointer arrow on the popup | |
CGRect popupFrame = graphPopupArrow.frame; | |
popupFrame.origin.x = 44; | |
graphPopupArrow.frame = popupFrame; | |
} | |
//Set the position via animation | |
CGRect popupFrame = CGRectMake(currentX,currentY+120,106,87); | |
[UIView beginAnimations:nil context:nil]; | |
[UIView setAnimationDuration:0.5]; | |
[UIView setAnimationDelay:0.0]; | |
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; | |
graphPopup.frame = popupFrame; | |
[UIView commitAnimations]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment