代码库> 其他> ASMediaFocusManager——允许用户点击任何缩放的图片,将图片放大
ASMediaFocusManager——允许用户点击任何缩放的图片,将图片放大
关注
上传者:ccsupport 分类:其他(Others)
查看次数:6825 下载次数:356
上传时间:2013-10-23 大小:2 KB
ASMediaFocusManager可以让用户通过点击app上任何缩放的图片,将图片放大。放大的图片自动变成全屏。再点击一下,图片会缩小回到原来的位置。

每张图片view可能会因原始图片的不同有不同的变化,放大和缩小的图片动画会考虑到这些图片的原始变化。



图片朝向
图片放大是会自动调整成水平屏幕的最大化的,即使你的main view controller只支持竖直屏幕。


如何使用

使用CocoaPods:
将pod 'ASMediaFocusManager'添加到Podfile中。

手动
将ASMediaFocusManager 复制到工程中

创建一个ASMediaFocusManager
实现它的delegate:ASMediaFocusDelegate
如果希望实现图片点击放大的功能就调用[ASMediaFocusManager installOnViews:]来声明view


实现
在希望加入放大图片功能的view controller处,加入以下代码:


- (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];
}



下面是一个delegate实现的例子。请根据你自己的情况进行参照修改以下代码:


#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
{
    return @"My title";
}




配置

以下是你可以进行配置的地方:

放大图片的背景颜色
动画的时长
关闭或打开动画
增加二指拨弹的手势来放大或缩小图片
通过点击或者Done按钮来关闭放大的图片


需要使用ARC


下载附件:
收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
提示
sina weixin mail 回到顶部