html实现图片浏览器,实现图片浏览器功能

周翼
2023-12-01

//

//ViewController.m//ScrollViewShowImage//

//Created by YouXianMing on 14-9-24.//Copyright (c) 2014年 YouXianMing. All rights reserved.//

#import "ViewController.h"

#import "NSObject+WeakRelated.h"typedefenum: NSUInteger {

Enum_blackView= 0x11,

Enum_snapView,

} ViewTag;@interfaceViewController ()

@property (strong, nonatomic) UIScrollView*scrollView;

@property (strong, nonatomic) UIImageView*imageView1;

@property (strong, nonatomic) UIImageView*imageView2;@end

@implementationViewController- (void)viewDidLoad {

[super viewDidLoad];//scorllView

_scrollView =[[UIScrollView alloc] initWithFrame:self.view.bounds];

_scrollView.contentSize= CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 3);

[self.view addSubview:_scrollView];//imageView1 + imageView2

_imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];

_imageView1.viewOrigin= CGPointMake(50, 50);

_imageView1.userInteractionEnabled= YES; //开启用户交互并添加手势

[_scrollView addSubview:_imageView1];

UITapGestureRecognizer*tap1 =[[UITapGestureRecognizer alloc] initWithTarget:self

action:@selector(tapMaxGestureEvent:)];

[_imageView1 addGestureRecognizer:tap1];

_imageView2= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];

_imageView2.viewOrigin= CGPointMake(50, 500);

_imageView2.userInteractionEnabled= YES; //开启用户交互并添加手势

[_scrollView addSubview:_imageView2];

UITapGestureRecognizer*tap2 =[[UITapGestureRecognizer alloc] initWithTarget:self

action:@selector(tapMaxGestureEvent:)];

[_imageView2 addGestureRecognizer:tap2];

}- (void)tapMaxGestureEvent:(UITapGestureRecognizer *)tap

{//获取UIWindow,之后在

UIWindow遇新是直朋能到 *window = [@"Window"recoverFromWeakDictionary];//变黑的背景

UIView *blackView =[[UIView alloc] initWithFrame:self.view.bounds];

blackView.tag=Enum_blackView;

blackView.alpha= 0;

blackView.backgroundColor=[UIColor blackColor];

[window addSubview:blackView];//复制view + tap手势

UIView *snapView =[tap.view snapshotViewAfterScreenUpdates:YES];

snapView.tag=Enum_snapView;

snapView.frame= [tap.view rectInView:window]; //复制view的frame值

snapView.alpha = 1;

snapView.weakRelatedObject=tap.view;

UITapGestureRecognizer*newTap =[[UITapGestureRecognizer alloc] initWithTarget:self

action:@selector(tapMinGestureEvent:)];

[snapView addGestureRecognizer:newTap];

[window addSubview:snapView];//动画

[UIView animateWithDuration:0.5f animations:^{

blackView.alpha= 1.f;

snapView.frame=[snapView ScaleAspectFit];

snapView.center=self.view.center;

}];

}- (void)tapMinGestureEvent:(UITapGestureRecognizer *)tap

{

UIWindow遇新是直朋能到*window = [@"Window"recoverFromWeakDictionary];

UIView*view1 =[window viewWithTag:Enum_snapView];

UIView*view2 =[window viewWithTag:Enum_blackView];

UIView*tapView =tap.view;

[UIView animateWithDuration:0.5f animations:^{

tapView.frame=[tap.view.weakRelatedObject rectInView:window];

view2.alpha= 0;

} completion:^(BOOL finished) {

[view2 removeFromSuperview];

[view1 removeFromSuperview];

}];

}@end

 类似资料: