Skip to content

Commit

Permalink
fixed the photo button for yelp map; minor xcode problems
Browse files Browse the repository at this point in the history
  • Loading branch information
gBit authored and gBit committed Mar 28, 2013
1 parent f24a434 commit e45d5f6
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 165 deletions.
9 changes: 6 additions & 3 deletions MappingMashupApp/FlickrMapViewController.m
Expand Up @@ -30,6 +30,7 @@ @interface FlickrMapViewController ()
NSString * photoTitleToPass;
NSString * photoThumbnailStringToPass;

__weak IBOutlet UIButton *photoOverlayButton;
__weak IBOutlet UIView *enlargedPhotoViewOutlet;
__weak IBOutlet MKMapView *mapView;
__weak IBOutlet UIView *loadingOverlay;
Expand Down Expand Up @@ -203,11 +204,11 @@ -(void) addPhotosToMap: (NSMutableArray*)photosArray
NSLog(@"%@", photosArray);
}

-(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id<MKAnnotation>)annotation
-(MKAnnotationView*)mapView:(MKMapView*)flickrMapView viewForAnnotation:(id<MKAnnotation>)annotation
{

UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotation"];
MKAnnotationView *annotationView = [flickrMapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotation"];
if([annotation isKindOfClass: [MKUserLocation class]])
{
return nil;
Expand Down Expand Up @@ -251,7 +252,7 @@ -(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id<MKAnnotati
//Re-enable refresh button
[UIView animateWithDuration:3.5
delay:2.0
options:nil
options:UIViewAnimationOptionTransitionNone
animations:^(void)
{
loadingOverlay.alpha = 0;
Expand Down Expand Up @@ -361,6 +362,8 @@ - (void)retrieveFullSizedImageForSelectedAnnotation:(Annotation*)annotation

CGRect scaledSuperView = CGRectMake(10.0f, 10.0f, imageViewWidth + 10, imageViewHeight + 10);
[photoViewerUIImageView.superview setFrame:scaledSuperView];
[photoOverlayButton setFrame:scaledSuperView];

}

- (IBAction)fullSizedPhotoTapped:(id)sender
Expand Down
134 changes: 70 additions & 64 deletions MappingMashupApp/YelpMapViewController.m
Expand Up @@ -100,40 +100,6 @@ - (void)viewDidLoad
[self retrieveFullSizedImageForSelectedPhoto:originPhotoThumbnailURL];
}

// working with existing structure, this passes in an NSString (as opposed to an Annotation)
// needs flexibility so it can be refactored and placed in the APIManager class
- (void)retrieveFullSizedImageForSelectedPhoto:(NSString*)photoThumbnailURL
{
// grab the medium sized version of the annotion image from flickr
NSString *photoFullSizeURLString = [photoThumbnailURL stringByReplacingOccurrencesOfString:@"s.jpg" withString:@"n.jpg"];
NSURL *photoFullSizeURL = [NSURL URLWithString:photoFullSizeURLString];
NSData *photoData = [NSData dataWithContentsOfURL:photoFullSizeURL];
UIImage *photoFullSize = [UIImage imageWithData:photoData];

// adjust the containing view and imageView to match the photo's aspect ratio
float photoWidth = photoFullSize.size.width;
float photoHeight = photoFullSize.size.height;
float photoAspectRatio = photoWidth/photoHeight;

// for this view, we've scaled it to 1/4 of the screen
float imageViewWidth = photoViewerUIImageView.frame.size.width;
float imageViewHeight = imageViewWidth/photoAspectRatio;

// frame positioning is also adjusted from flickr view
CGRect scaledImageView = CGRectMake(3.0f, 3.0f, imageViewWidth, imageViewHeight);
[photoViewerUIImageView setFrame:scaledImageView];
photoViewerUIImageView.image = photoFullSize;

// now the superview
CGRect scaledSuperView = CGRectMake(5.0f, 5.0f, imageViewWidth + 6, imageViewHeight + 6);
[photoViewerUIImageView.superview setFrame:scaledSuperView];

// and last, but not least, the button
CGRect scaledButton = CGRectMake(0.0f, 0.0f, scaledSuperView.size.width + 10, scaledSuperView.size.height + 10);
[photoViewerButton setFrame:scaledButton];
}


# pragma mark - User Location Methods
-(void) didReceiveYelpData:(NSMutableArray *)venuesArray
{
Expand Down Expand Up @@ -212,7 +178,7 @@ -(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id<MKAnnotati
return annotationView;
}

//Method for creating a map overlay
// Method for creating a map overlay
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKCircle class]])
Expand All @@ -238,19 +204,19 @@ - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *
//If statement to prevent crash if you tap Current Location pin.
if(![view.annotation isKindOfClass:[MKUserLocation class]])
{
selectedAnnotation = view.annotation;

Business *selectedBusiness = [NSEntityDescription insertNewObjectForEntityForName:@"Business" inManagedObjectContext:managedObjectContext];

selectedBusiness.latitude = selectedAnnotation.latitude;
selectedBusiness.longitude = selectedAnnotation.longitude;
selectedBusiness.name = selectedAnnotation.name;
selectedBusiness.yelpURLString = selectedAnnotation.yelpURLString;
selectedBusiness.viewDate = selectedAnnotation.viewDate;
selectedAnnotation = view.annotation;

Business *selectedBusiness = [NSEntityDescription insertNewObjectForEntityForName:@"Business"
inManagedObjectContext:managedObjectContext];

selectedBusiness.latitude = selectedAnnotation.latitude;
selectedBusiness.longitude = selectedAnnotation.longitude;
selectedBusiness.name = selectedAnnotation.name;
selectedBusiness.yelpURLString = selectedAnnotation.yelpURLString;
selectedBusiness.viewDate = selectedAnnotation.viewDate;
NSLog(@"Selected business view date:%@", selectedAnnotation.viewDate);
selectedBusiness.phone = selectedAnnotation.phone;


selectedBusiness.phone = selectedAnnotation.phone;

NSError *error;
if (![managedObjectContext save:&error])
{
Expand All @@ -259,6 +225,63 @@ - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *
}
}

// User taps on disclosure button to see more Yelp data. //
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"This is the method we want!");
[self performSegueWithIdentifier:@"toYelpWebPage" sender:nil];
}

-(void) bookmarkButtonPressed
{
NSLog(@"User pressed button to go to bookmarks");
[self performSegueWithIdentifier: @"yelpPageToBookmarks" sender:self];
}

- (IBAction)largePhotoTapped:(id)sender {
[yelpMapView selectAnnotation:originAnnotation animated:YES];
}

// working with existing structure, this passes in an NSString (as opposed to an Annotation)
// needs flexibility so it can be refactored and placed in the APIManager class
- (void)retrieveFullSizedImageForSelectedPhoto:(NSString*)photoThumbnailURL
{
// grab the medium sized version of the annotion image from flickr
NSString *photoFullSizeURLString = [photoThumbnailURL stringByReplacingOccurrencesOfString:@"s.jpg" withString:@"n.jpg"];
NSURL *photoFullSizeURL = [NSURL URLWithString:photoFullSizeURLString];
NSData *photoData = [NSData dataWithContentsOfURL:photoFullSizeURL];
UIImage *photoFullSize = [UIImage imageWithData:photoData];

// adjust the containing view and imageView to match the photo's aspect ratio
float photoWidth = photoFullSize.size.width;
float photoHeight = photoFullSize.size.height;
float photoAspectRatio = photoWidth/photoHeight;

// for this view, we've scaled it to 1/4 of the screen
float imageViewWidth = photoViewerUIImageView.frame.size.width;
float imageViewHeight = imageViewWidth/photoAspectRatio;

// since portrait images frequently obscure the annotation, we'll scale them down a bit
if (photoAspectRatio < 1)
{
imageViewWidth *= 0.75f;
imageViewHeight *= 0.75f;
}

// frame positioning is also adjusted from flickr view
CGRect scaledImageView = CGRectMake(3.0f, 3.0f, imageViewWidth, imageViewHeight);
[photoViewerUIImageView setFrame:scaledImageView];
photoViewerUIImageView.image = photoFullSize;

// now the superview
CGRect scaledSuperView = CGRectMake(5.0f, 5.0f, imageViewWidth + 6, imageViewHeight + 6);
[photoViewerUIImageView.superview setFrame:scaledSuperView];

// and last, but not least, the button
CGRect scaledButton = CGRectMake(0.0f, 0.0f, scaledSuperView.size.width + 10, scaledSuperView.size.height + 10);
[photoViewerButton setFrame:scaledButton];
}

//Masking method
- (UIImage*) createMaskWith: (UIImage *)maskImage onImage:(UIImage*) subjectImage
{
Expand All @@ -278,20 +301,6 @@ - (UIImage*) createMaskWith: (UIImage *)maskImage onImage:(UIImage*) subjectImag
return finalImage;
}

//
// User taps on disclosure button to see more Yelp data.
//
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"This is the method we want!");
[self performSegueWithIdentifier:@"toYelpWebPage" sender:nil];
}

-(void) bookmarkButtonPressed
{
NSLog(@"User pressed button to go to bookmarks");
[self performSegueWithIdentifier: @"yelpPageToBookmarks" sender:self];
}

# pragma mark - Transitions

Expand Down Expand Up @@ -327,7 +336,4 @@ - (void)didReceiveMemoryWarning
// Dispose of any resources that can be recreated.
}

- (IBAction)largePhotoTapped:(id)sender {
[yelpMapView selectAnnotation:originAnnotation animated:YES];
}
@end
9 changes: 4 additions & 5 deletions MappingMashupApp/YelpWebPageBrowser.m
Expand Up @@ -69,7 +69,7 @@ - (void)viewDidLoad

[UIView animateWithDuration:0.0
delay:0.0
options: UIViewAnimationCurveEaseIn
options: UIViewAnimationOptionCurveEaseIn
animations:^{
popoutView.center = CGPointMake(popoutView.center.x, popoutView.center.y+200);
popoutView.alpha = 0;
Expand All @@ -82,10 +82,10 @@ - (void)viewDidLoad
forwardButton.enabled = NO;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
- (void)webViewDidFinishLoad:(UIWebView *)loadingWebView
{
//Code to manage back/forward buttons
if (![webView canGoBack])
if (![loadingWebView canGoBack])
{
backButton.enabled = NO;
}
Expand All @@ -94,7 +94,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
backButton.enabled = YES;
}

if (![webView canGoForward])
if (![loadingWebView canGoForward])
{
forwardButton.enabled = NO;
}
Expand Down Expand Up @@ -196,7 +196,6 @@ -(Business*) fetchBusinessShownInWebpage
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc]init];
NSFetchedResultsController * fetchResultsController;

NSString *predicateURLString = [yelpURLString urlencode];
//Now customize your search! We'd want to switch this to see if isBookmarked == true
NSArray * sortDescriptors = [[NSArray alloc] initWithObjects:nil];
NSPredicate * predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"yelpURLString == '%@'", yelpURLString]];
Expand Down

0 comments on commit e45d5f6

Please sign in to comment.