Permalink
Browse files

fixed the photo button for yelp map; minor xcode problems

  • Loading branch information...
gBit gBit
gBit authored and gBit committed Mar 28, 2013
1 parent f24a434 commit e45d5f632d071e139e2ba0c6e5ec5bb2239a0b79
@@ -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;
@@ -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;
@@ -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;
@@ -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
@@ -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
{
@@ -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]])
@@ -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])
{
@@ -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
{
@@ -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
@@ -327,7 +336,4 @@ - (void)didReceiveMemoryWarning
// Dispose of any resources that can be recreated.
}
-- (IBAction)largePhotoTapped:(id)sender {
- [yelpMapView selectAnnotation:originAnnotation animated:YES];
-}
@end
@@ -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;
@@ -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;
}
@@ -94,7 +94,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
backButton.enabled = YES;
}
- if (![webView canGoForward])
+ if (![loadingWebView canGoForward])
{
forwardButton.enabled = NO;
}
@@ -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]];
Oops, something went wrong.

0 comments on commit e45d5f6

Please sign in to comment.