IOS asmediafocusmanager thumbnail Preview

Source: Internet
Author: User
Tags file url

During the Sina Weibo client process, a third-party library was accidentally found on the internet due to the problem of thumbnail enlargement and display of Weibo content. It is very suitable for this job. After a little research, it is probably usable.


The third-party library asmediafocusmanager can zoom in the image through simple touch operations and automatically fill the full screen in an animation. Then, you can touch the image again or click done to restore the original size.

Yes: https://github.com/autresphere/ASMediaFocusManager

The following describes this usage in the official document (the downloaded folder contains a GIF animation demonstration and you will know what is going on ).

Asmediafocusmanager

Asmediafocusmanager gives the ability to focus on any thumbnail image by a simple tap. The thumbnail image is automatically animated to a focused fullscreen Image view. Another tap on the focused view shrinks the image back
To its initial position.

You can use the class library asmediafocusmanager to zoom in the image by clicking a thumbnail, and fill the full screen in an animation; click it again to restore the original thumbnail.

Each thumbnail image view may have its own transform, the focus and defocus animations take care of any initial transform. Works on iPhone and iPad.

Orientation

The focused view is automatically adapted to the screen orientation even if your main view controller is portrait only.

The view automatically adapts to the orientation of the screen.

Because orientation management is different between iOS 5 and 6, this class is for iOS 6 only (although it shoshould not be hard to adapt it to iOS 5 ).

Orientation management is different in ios5 and ios6, and this class library only supports io6 (although it is not difficult to implement ios5 through some processing ).

Use it

Copy the wholeASMediaFocusManagerFolder
In your project. Import this class library to your project.

  • CreateAsmediafocusmanager (create an instance)
  • Implement its delegate (ASMediaFocusDelegate)
    (Proxy method)
  • Declare all your views that you want to be focusable by calling[Asmediafocusmanager
    Installonviews:] (call method)
Implementing

In your view controller where some image views need focus feature, add this code.

- (void)viewDidLoad{    [super viewDidLoad];    self.mediaFocusManager = [[ASMediaFocusManager alloc] init];    self.mediaFocusManager.delegate = self;    // Tells which views need to be focusable. You can put your image views in an array and give it to the focus manager.    [self.mediaFocusManager installOnViews:self.imageViews];}

Here is an example of a delegate implementation. Please adapt the Code to your context.

#pragma mark - ASMediaFocusDelegate// 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{    return ((UIImageView *)view).image;}// Returns the final focused frame for this media view. This frame is usually a full screen frame.- (CGRect)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager finalFrameforView:(UIView *)view{    return self.parentViewController.view.bounds;}// Returns the view controller in which the focus controller is going to be added.// This can be any view controller, full screen or not.- (UIViewController *)parentViewControllerForMediaFocusManager:(ASMediaFocusManager *)mediaFocusManager{    return self.parentViewController;}// Returns an URL where the image is stored. This URL is used to create an image at full screen. The URL may be local (file://) or distant (http://).- (NSURL *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager mediaURLForView:(UIView *)view{    NSString *path;    NSString *name;    NSURL *url;    // Here, images are accessed through their name "1f.jpg", "2f.jpg", …    name = [NSString stringWithFormat:@"%df", ([self.imageViews indexOfObject:view] + 1)];    path = [[NSBundle mainBundle] pathForResource:name ofType:@"jpg"];    url = [NSURL fileURLWithPath:path];    return url;}// Returns the title for this media view. Return nil if you don't want any title to appear.- (NSString *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager titleForView:(UIView *)view{    NSString *title;        title = [NSString stringWithFormat:@"Image %@", [self mediaFocusManager:mediaFocusManager mediaURLForView:view].lastPathComponent];        return @"Of course, you can zoom in and out on the image.";}
Note: The first three proxy methods do not need to be modified. The fourth method returns a URL. If a large image with a thumbnail already exists locally, then, the URL of the file is returned (the Code of how to find the File URL is provided in the preceding example). If the thumbnail is downloaded over the network, the URL of the large image is directly returned. The fifth method is to return the file name of the big image to be synchronously displayed when the big image is displayed. Of course, you can also return any string that you want to display at the same time when the big image is displayed. Configure (you can also set the following parameters accordingly)

Here is the things you can configure:

  • Focused background color
  • Animation duration
  • Enable/disable elastic Animation
  • Enable/disable zooming by Pinch
  • Close focused view either by tap or through a "done" button (in the old version, the "done" button is used, but in the new version)
Arc

Asmediafocusmanager needs arc. (This class library uses the arc feature)

Example

Next I will try to write a simple demo by myself. Of course, a demo is included in the download of the class library, which is quite good. Let's see what the demo knows.

Follow the steps mentioned above (using a single view template ).

- (void)viewDidLoad{    [super viewDidLoad];        UIImageView *iView = [[UIImageView alloc] initWithFrame:CGRectMake(35,10, 250, 143)];    iView.image = [UIImage imageNamed:@"1.jpg"];    [self.view addSubview:iView];        self.mediaFocusManager = [[ASMediaFocusManager alloc] init];    self.mediaFocusManager.delegate = self;    [self.mediaFocusManager installOnView:iView];}#pragma mark - ASMediaFocusDelegate- (UIImage *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager imageForView:(UIView *)view{    return ((UIImageView *)view).image;}- (CGRect)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager finalFrameforView:(UIView *)view{    //    return self.parentViewController.view.bounds;    return self.view.bounds;}- (UIViewController *)parentViewControllerForMediaFocusManager:(ASMediaFocusManager *)mediaFocusManager{    //    return self.parentViewController;    return self;}- (NSURL *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager mediaURLForView:(UIView *)view{    NSString *path;    NSString *name;    NSURL *url;        name = [NSString stringWithFormat:@"%df", 1];    path = [[NSBundle mainBundle] pathForResource:name ofType:@"jpg"];        url = [NSURL fileURLWithPath:path];    return url;}- (NSString *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager titleForView:(UIView *)view;{    NSString *title;        title = [NSString stringWithFormat:@"Image %@", [self mediaFocusManager:mediaFocusManager mediaURLForView:view].lastPathComponent];        //    return @"Of course, you can zoom in and out on the image.";    return title;}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    // Override point for customization after application launch.    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    [self.window setBackgroundColor:[UIColor whiteColor]];    [self.window makeKeyAndVisible];        ViewController *root = [[ViewController alloc]initWithNibName:nil bundle:nil];    self.window.rootViewController = root;    return YES;}

Note: The code is simple.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.