Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit e7a898b8cd3c35e4bddb0c781da7460207806809 @autresphere committed Jan 11, 2013
Showing with 2,188 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +18 −0 ASMediaFocusManager/ASMediaFocusController.h
  3. +168 −0 ASMediaFocusManager/ASMediaFocusController.m
  4. +35 −0 ASMediaFocusManager/ASMediaFocusManager.h
  5. +166 −0 ASMediaFocusManager/ASMediaFocusManager.m
  6. +50 −0 Example/ASMediaFocus/ASMediaFocusExemple-Info.plist
  7. +14 −0 Example/ASMediaFocus/ASMediaFocusExemple-Prefix.pch
  8. +19 −0 Example/ASMediaFocus/AppDelegate.h
  9. +52 −0 Example/ASMediaFocus/AppDelegate.m
  10. BIN Example/ASMediaFocus/Default-568h@2x.png
  11. BIN Example/ASMediaFocus/Default.png
  12. BIN Example/ASMediaFocus/Default@2x.png
  13. +15 −0 Example/ASMediaFocus/MainViewController.h
  14. +33 −0 Example/ASMediaFocus/MainViewController.m
  15. +166 −0 Example/ASMediaFocus/en.lproj/ASMediaFocusController.xib
  16. +266 −0 Example/ASMediaFocus/en.lproj/ASMediaThumbnailsViewController~ipad.xib
  17. +362 −0 Example/ASMediaFocus/en.lproj/ASMediaThumbnailsViewController~iphone.xib
  18. +2 −0 Example/ASMediaFocus/en.lproj/InfoPlist.strings
  19. +18 −0 Example/ASMediaFocus/main.m
  20. +423 −0 Example/ASMediaFocusExemple.xcodeproj/project.pbxproj
  21. +19 −0 Example/ASMediaThumbnailsViewController.h
  22. +63 −0 Example/ASMediaThumbnailsViewController.m
  23. +246 −0 Example/MainViewController.xib
  24. BIN Example/Resources/media/full/1f.jpg
  25. BIN Example/Resources/media/full/2f.jpg
  26. BIN Example/Resources/media/full/3f.jpg
  27. BIN Example/Resources/media/full/4f.jpg
  28. BIN Example/Resources/media/thumbnails/1.jpg
  29. BIN Example/Resources/media/thumbnails/2.jpg
  30. BIN Example/Resources/media/thumbnails/3.jpg
  31. BIN Example/Resources/media/thumbnails/4.jpg
  32. +24 −0 Readme.md
  33. BIN Screenshots/iPhone1.jpg
  34. BIN Screenshots/iPhone2.jpg
  35. BIN Screenshots/iPhone3.jpg
  36. +20 −0 license
@@ -0,0 +1,9 @@
+build/
+.DS_Store
+*.pbxuser
+*.perspective
+*.perspectivev3
+*.mode1v3
+*.mode2v3
+*.xcworkspace
+xcuserdata
@@ -0,0 +1,18 @@
+//
+// ASMediaFocusViewController.h
+// ASMediaFocusManager
+//
+// Created by Philippe Converset on 21/12/12.
+// Copyright (c) 2012 AutreSphere. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ASMediaFocusController : UIViewController
+
+@property (strong, nonatomic) IBOutlet UIImageView *mainImageView;
+@property (strong, nonatomic) IBOutlet UIView *contentView;
+
+- (void)setImageFrame:(CGRect)frame;
+
+@end
@@ -0,0 +1,168 @@
+//
+// ASMediaFocusViewController.m
+// ASMediaFocusManager
+//
+// Created by Philippe Converset on 21/12/12.
+// Copyright (c) 2012 AutreSphere. All rights reserved.
+//
+
+#import "ASMediaFocusController.h"
+
+static NSTimeInterval const kDefaultOrientationAnimationDuration = 0.4;
+
+@interface ASMediaFocusController ()
+
+@property (nonatomic, assign) UIDeviceOrientation previousOrientation;
+
+@end
+
+@implementation ASMediaFocusController
+
+- (void)viewDidUnload
+{
+ [self setMainImageView:nil];
+ [self setContentView:nil];
+ [super viewDidUnload];
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
+ [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
+}
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
+ [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
+}
+
+- (NSUInteger)supportedInterfaceOrientations
+{
+ return UIInterfaceOrientationMaskPortrait;
+}
+
+- (BOOL)isParentSupportingInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
+{
+ switch(toInterfaceOrientation)
+ {
+ case UIInterfaceOrientationPortrait:
+ return [self.parentViewController supportedInterfaceOrientations] & UIInterfaceOrientationMaskPortrait;
+
+ case UIInterfaceOrientationPortraitUpsideDown:
+ return [self.parentViewController supportedInterfaceOrientations] & UIInterfaceOrientationMaskPortraitUpsideDown;
+
+ case UIInterfaceOrientationLandscapeLeft:
+ return [self.parentViewController supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeLeft;
+
+ case UIInterfaceOrientationLandscapeRight:
+ return [self.parentViewController supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeRight;
+ }
+}
+
+- (void)updateOrientationAnimated:(BOOL)animated
+{
+ CGAffineTransform transform;
+ CGRect frame;
+ NSTimeInterval duration = kDefaultOrientationAnimationDuration;
+
+ if([UIDevice currentDevice].orientation == self.previousOrientation)
+ return;
+
+ if((UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation) && UIInterfaceOrientationIsLandscape(self.previousOrientation))
+ || (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation) && UIInterfaceOrientationIsPortrait(self.previousOrientation)))
+ {
+ duration *= 2;
+ }
+
+ if(([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait)
+ || [self isParentSupportingInterfaceOrientation:[UIDevice currentDevice].orientation])
+ {
+ transform = CGAffineTransformIdentity;
+ }
+ else
+ {
+ switch ([UIDevice currentDevice].orientation)
+ {
+ case UIInterfaceOrientationLandscapeLeft:
+ if(self.parentViewController.interfaceOrientation == UIInterfaceOrientationPortrait)
+ {
+ transform = CGAffineTransformMakeRotation(-M_PI_2);
+ }
+ else
+ {
+ transform = CGAffineTransformMakeRotation(M_PI_2);
+ }
+ break;
+
+ case UIInterfaceOrientationLandscapeRight:
+ if(self.parentViewController.interfaceOrientation == UIInterfaceOrientationPortrait)
+ {
+ transform = CGAffineTransformMakeRotation(M_PI_2);
+ }
+ else
+ {
+ transform = CGAffineTransformMakeRotation(-M_PI_2);
+ }
+ break;
+
+ case UIInterfaceOrientationPortrait:
+ transform = CGAffineTransformIdentity;
+ break;
+
+ case UIInterfaceOrientationPortraitUpsideDown:
+ transform = CGAffineTransformMakeRotation(M_PI);
+ break;
+
+ case UIDeviceOrientationFaceDown:
+ case UIDeviceOrientationFaceUp:
+ case UIDeviceOrientationUnknown:
+ return;
+ }
+ }
+
+ if(animated)
+ {
+ frame = self.contentView.frame;
+ [UIView animateWithDuration:duration
+ animations:^{
+ self.contentView.transform = transform;
+ self.contentView.frame = frame;
+ }];
+ }
+ else
+ {
+ frame = self.contentView.frame;
+ self.contentView.transform = transform;
+ self.contentView.frame = frame;
+ }
+ self.previousOrientation = [UIDevice currentDevice].orientation;
+}
+
+#pragma mark - Public
+- (void)setImageFrame:(CGRect)frame
+{
+ CGRect initialFrame;
+
+ // Trick to keep the right animation on the image frame (if this method is called in an animation block).
+ // The image frame shoud animate from its current frame to a final frame.
+ // The final frame is computed by taking care of a possible rotation regarding the current device orientation, done by calling updateOrientationAnimated.
+ // As this method changes the image frame, it also replaces the current animation on the image view, which is not wanted.
+ // Thus to recreate the right animation, the image frame is set back to its inital frame then to its final frame.
+ // This very last frame operation recreates the right frame animation.
+ initialFrame = self.mainImageView.frame;
+ self.mainImageView.frame = frame;
+ [self updateOrientationAnimated:NO];
+ frame = self.mainImageView.frame;
+ self.mainImageView.frame = initialFrame;
+ self.mainImageView.frame = frame;
+}
+
+#pragma mark - Notifications
+- (void)orientationDidChangeNotification:(NSNotification *)notification
+{
+ [self updateOrientationAnimated:YES];
+}
+@end
@@ -0,0 +1,35 @@
+//
+// ASMediaFocusManager.h
+// ASMediaFocusManager
+//
+// Created by Philippe Converset on 11/12/12.
+// Copyright (c) 2012 AutreSphere. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class ASMediaFocusManager;
+
+@protocol ASMediasFocusDelegate <NSObject>
+
+// Returns an image that represents the media view. This image is used in the focusing animation view. It is usually a small image.
+- (UIImage *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager imageForView:(UIView *)view;
+// Returns the final focused frame for this media view. This frame is usually a full screen frame.
+- (CGRect)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager finalFrameforView:(UIView *)view;
+// Returns the view controller in which the focus controller is going to ba added. This can be any view controller, full screen or not.
+- (UIViewController *)parentViewControllerForMediaFocusManager:(ASMediaFocusManager *)mediaFocusManager;
+// Returns a local media path, it must be an image path. This path is used to create an image at full screen.
+- (NSString *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager mediaPathForView:(UIView *)view;
+
+@end
+
+
+@interface ASMediaFocusManager : NSObject
+
+@property (nonatomic, assign) id<ASMediasFocusDelegate> delegate;
+@property (nonatomic, assign) NSTimeInterval animationDuration;
+@property (nonatomic, strong) UIColor *backgroundColor;
+
+- (void)installOnViews:(NSArray *)views;
+
+@end
Oops, something went wrong.

0 comments on commit e7a898b

Please sign in to comment.