-(void)tapAction:(UITapGestureRecognizer *)tap{
CGFloat offsetX = (self.myScrollView.bounds.size.width > self.myScrollView.contentSize.width)?(self.myScrollView.bounds.size.width - self.myScrollView.contentSize.width)/2 : 0.0;
CGFloat offsetY = (self.myScrollView.bounds.size.height > self.myScrollView.contentSize.height)?(self.myScrollView.bounds.size.height - self.myScrollView.contentSize.height)/2 : 0.0;
CGPoint touchPoint = [tap locationInView:self.myScrollView];
if ((self.myScrollView.zoomScale >= metroScale) && (self.myScrollView.zoomScale < metroScale*2)) {
///x轴的逻辑是正确的,但是y轴不是从0开始的,,上边有导航栏呢。。。。。
[self.myScrollView zoomToRect:CGRectMake(((touchPoint.x-offsetX)/metroScale), ((touchPoint.y-offsetY)/metroScale)-kNavigationBarHeight-StateBarHeight, metroScale*2, metroScale*2) animated:YES];
[self.myScrollViewsetZoomScale:metroScale*2animated:YES];
} elseif((self.myScrollView.zoomScale >= metroScale*2)&&(self.myScrollView.zoomScale < metroScale*3)){
///x轴的逻辑是正确的,但是y轴不是从0开始的,,上边有导航栏呢。。。。。
[self.myScrollView zoomToRect:CGRectMake(((touchPoint.x-offsetX)/(metroScale*2)), ((touchPoint.y-offsetY)/(metroScale*2))-kNavigationBarHeight-StateBarHeight, metroScale*4, metroScale*4) animated:YES];
[self.myScrollViewsetZoomScale:metroScale*4animated:YES];
}else{
[self.myScrollViewsetZoomScale:metroScaleanimated:YES];
}
}
///下面的一个方法,可以实现从点击的地方开始放大,效果不错。。。
-(void)tapAction:(UITapGestureRecognizer *)tap{
-(void)tapAction:(UITapGestureRecognizer *)tap{
CGFloat offsetX = (self.myScrollView.bounds.size.width > self.myScrollView.contentSize.width)?(self.myScrollView.bounds.size.width - self.myScrollView.contentSize.width)/2 : 0.0;
CGFloat offsetY = (self.myScrollView.bounds.size.height > self.myScrollView.contentSize.height)?(self.myScrollView.bounds.size.height - self.myScrollView.contentSize.height)/2 : 0.0;
CGPoint touchPoint = [tap locationInView:self.myScrollView];
if (self.myScrollView.zoomScale != metroScale) {
[self.myScrollViewsetZoomScale:metroScaleanimated:YES];
} else {
///x轴的逻辑是正确的,但是y轴不是从0开始的,,上边有导航栏呢。。。。。
[self.myScrollView zoomToRect:CGRectMake(((touchPoint.x-offsetX)/metroScale), ((touchPoint.y-offsetY)/metroScale)-kNavigationBarHeight-StateBarHeight, metroScale*3, metroScale*3) animated:YES];
[self.myScrollViewsetZoomScale:metroScale*3animated:YES];
}
}
}
///下面是核心代码
///添加touch事件
UITapGestureRecognizer *myTapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tapAction:)];
myTapGesture.numberOfTapsRequired=2;//默认为1.表示点击的次数。
[self.myScrollView addGestureRecognizer:myTapGesture];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
returnself.myImageV;
}
-(void)tapAction:(UITapGestureRecognizer *)tap{
CGFloat offsetX = (self.myScrollView.bounds.size.width > self.myScrollView.contentSize.width)?(self.myScrollView.bounds.size.width - self.myScrollView.contentSize.width)/2 : 0.0;
CGFloat offsetY = (self.myScrollView.bounds.size.height > self.myScrollView.contentSize.height)?(self.myScrollView.bounds.size.height - self.myScrollView.contentSize.height)/2 : 0.0;
CGPoint touchPoint = [tap locationInView:self.myScrollView];
kNSLog(@"双击metroScale == %f,,%f,,%f",metroScale,offsetX,offsetY);
if (self.myScrollView.zoomScale != metroScale) {
[self.myScrollViewsetZoomScale:metroScaleanimated:YES];
} else {
///x轴的逻辑是正确的,但是y轴不是从0开始的,,上边有导航栏呢。。。。。
[self.myScrollView zoomToRect:CGRectMake(((touchPoint.x-offsetX)/metroScale), ((touchPoint.y-offsetY)/metroScale)-kNavigationBarHeight-StateBarHeight, 1, 1) animated:YES];
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
float minzoomx = self.myScrollView.frame.size.width / self.myImageV.size.width;
float minzoomy = self.myScrollView.frame.size.height / self.myImageV.size.height;
if(scrollView.zoomScale > MIN(minzoomx, minzoomy))
{
// [self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2)/minzoomx, (scrollView.frame.size.height / 2)/minzoomy)];
NSLog(@"上面。。。。。。。。。。。。。。。");
}else{
NSLog(@"下面。");
if (minzoomy>minzoomx) {
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2)/MIN(minzoomx, minzoomy), (scrollView.frame.size.height / 2))];
}else{
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2), (scrollView.frame.size.height / 2)/MIN(minzoomx, minzoomy))];
}
}
}
///上面是核心代码
///前面的只是表面上好的。。。在最后才真正是对的。。。。。
self.myScrollView.delegate = self;
float minzoomx = self.myScrollView.frame.size.width / self.myImageV.size.width;
float minzoomy = self.myScrollView.frame.size.height / self.myImageV.size.height;
self.myScrollView.minimumZoomScale = MIN(minzoomx, minzoomy); //最小缩放到当前ScrollView的大小比例
self.myScrollView.maximumZoomScale = 3.0f; //最大缩放到图片的3倍
///设置地铁图的初始化位置。。。
self.myScrollView.zoomScale = MIN(minzoomx, minzoomy);
///这个也不能少
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
returnself.myImageV;
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
if(scrollView.zoomScale < 1.0)
{
UIImageView *imageView = [scrollView.subviews lastObject];
[self.myImageV setCenter:CGPointMake(scrollView.frame.size.width / 2, scrollView.frame.size.height / 2)];
}
}
////应该用下面的才行。。。
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
float minzoomx = self.myScrollView.frame.size.width / self.myImageV.size.width;
float minzoomy = self.myScrollView.frame.size.height / self.myImageV.size.height;
if(scrollView.zoomScale > 1.0)
{
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2)/minzoomx, (scrollView.frame.size.height / 2)/minzoomy)];
}else{
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2), (scrollView.frame.size.height / 2))];
}
}
////真正行的。。。。。。。
//
// ShowPDFViewController.m
// iTotemFramework
//
// Created by apple on 14-3-5.
// Copyright (c) 2014年 iTotemStudio. All rights reserved.
//
#import "ShowPDFViewController.h"
#import "UIImage+PDF.h"
@interfaceShowPDFViewController ()
@end
@implementation ShowPDFViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.myData = [NSMutableData data];
}
returnself;
}
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.navigationItemsetNewTitle:self.myName];
[self.navigationItemsetBackItemWithTarget:selfaction:@selector(back) title:nil];
[self.navigationItemsetRightItemWithTarget:selfaction:@selector(rightAction:) image:@"DT_share.png"];
}
///分享的方法。。。。。
-(void)rightAction:(id)sender{
NSString *tempText = [NSStringstringWithFormat:@"这是一张高清%@地铁图,分享自世界邦 - 全球地铁图APP。你也快来试试吧。应用下载地址:%@",self.myName,kAPPURL];
[UMSocialSnsServicepresentSnsIconSheetView:self
appKey:kUMappKey
shareText:tempText
shareImage:self.myShareImage
shareToSnsNames:[NSArrayarrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline,nil]
delegate:nil];
///微信,朋友圈分享。。
//设置微信分享应用类型,用户点击消息将跳转到应用,或者到下载页面
//UMSocialWXMessageTypeImage 为纯图片类型
[UMSocialDatadefaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
// [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeImage;
//分享图文样式到微信朋友圈显示字数比较少,只显示分享标题
[UMSocialDatadefaultData].extConfig.title = @"朋友圈分享内容";
//设置微信好友或者朋友圈的分享url,下面是微信好友,微信朋友圈对应wechatTimelineData
[UMSocialDatadefaultData].extConfig.wechatSessionData.url = @"http://www.shijiebang.com/topic/mobile/railway/";
[UMSocialDatadefaultData].extConfig.wechatTimelineData.url = @"http://www.shijiebang.com/topic/mobile/railway/";
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[MobClickendLogPageView:@"显示地铁图页面"];
}
///页面出来后。。。
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if ([kUserDefault objectForKey:self.myURL]!=NULL) {
[self showSubway];
}
else{
if (![ViewControllerFactoryisnetworkOK]) {
// [self.view.window showHUDWithText:@"该地铁图还没有下载,请检查联网!" Type:ShowLoading Enabled:YES];
[ViewControllerFactoryshowMessageAlert:@"该地铁图还没有下载,请检查联网!"];
}else{
NSURL *url = [NSURL URLWithString:self.myURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//发起请求,定义代理
[NSURLConnectionconnectionWithRequest:request delegate:self];
flag = 0;
///初始化一个imageView
self.tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 90)];
self.tempView.backgroundColor = [UIColorclearColor];
self.tempView.center = CGPointMake(kScreenWidth/2, (kScreenHeight-kNavigationBarHeight-kStateBarHeight)/2);
self.tempImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 60, 55)];
self.tempLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 55, 80, 30)];
self.tempLabel.textAlignment = NSTextAlignmentCenter;
self.tempLabel.font = [UIFont fontWithName:@"Arial" size:13];
self.tempLabel.backgroundColor = [UIColorclearColor];
[self.tempViewaddSubview:self.tempImageView];
[self.tempView addSubview:self.tempLabel];
[self.view addSubview:self.tempView];
[self.view bringSubviewToFront:self.tempView];
}
}
}
///页面出来前
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[MobClickendLogPageView:@"显示地铁图页面"];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if(httpResponse && [httpResponse respondsToSelector:@selector(allHeaderFields)]){
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
total_ = [[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue];
}
}
// 分批返回数据
- (void)connection:(NSURLConnection *) connection didReceiveData:(NSData *)data {
[self.myData appendData:data];
double a = [self.myData length];
float jindu = a/total_;
int imageFlag = (int)(jindu*24);
NSString *imageString = [NSString stringWithFormat:@"%d",imageFlag];
self.tempLabel.text = [NSString stringWithFormat:@"加载中%d%%",(int)(jindu*100)];
self.tempImageView.image = kImageNamed(imageString);
}
// 数据完全返回完毕
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
///下面的两句其实已经给imageView赋值了。。。。。
UIImage *tempImage = [UIImageoriginalSizeImageWithPDFData:self.myData];
self.myImageV.image = tempImage;
[self.tempViewremoveFromSuperview];
tempWidth = tempImage.size.width;
tempHeight = tempImage.size.height;
self.myImageV.size = CGSizeMake(tempWidth, tempHeight);///关键是这句话。。。。。
self.myScrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-kNavigationBarHeight-StateBarHeight);
self.myScrollView.contentSize = CGSizeMake(self.myImageV.size.width, self.myImageV.size.height);
self.myScrollView.delegate = self;
float minzoomx = self.myScrollView.frame.size.width / tempWidth;
float minzoomy = self.myScrollView.frame.size.height / tempHeight;
self.myScrollView.minimumZoomScale = MIN(minzoomx, minzoomy); //最小缩放到当前ScrollView的大小比例
self.myScrollView.maximumZoomScale = 3.0f; //最大缩放到图片的3倍
///设置地铁图的初始化位置。。。
self.myScrollView.zoomScale = MIN(minzoomx, minzoomy);
[kUserDefaultsetObject:self.myDataforKey:self.myURL];
[kUserDefaultsynchronize];
self.myShareImage = [ViewControllerFactoryyasuoCameraImage:tempImage];///这是为了分享用的。。。。。。
///添加touch事件
UITapGestureRecognizer *myTapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tapAction:)];
self.myImageV.userInteractionEnabled = YES;
myTapGesture.numberOfTapsRequired=2;//默认为1.表示点击的次数。
[self.myImageV addGestureRecognizer:myTapGesture];
}
-(void)showSubway{
UIImage *tempImage = [UIImage originalSizeImageWithPDFData:[kUserDefault objectForKey:self.myURL]];
self.myImageV.image = tempImage;
tempWidth = tempImage.size.width;
tempHeight = tempImage.size.height;
self.myImageV.size = CGSizeMake(tempWidth, tempHeight);///关键是这句话。。。。。
self.myScrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-kNavigationBarHeight-StateBarHeight);
self.myScrollView.delegate = self;
float minzoomx = self.myScrollView.frame.size.width / tempWidth;
float minzoomy = self.myScrollView.frame.size.height / tempHeight;
self.myScrollView.minimumZoomScale = MIN(minzoomx, minzoomy); //最小缩放到当前ScrollView的大小比例
self.myScrollView.maximumZoomScale = 3.0f; //最大缩放到图片的3倍
///设置地铁图的初始化位置。。。
self.myScrollView.zoomScale = MIN(minzoomx, minzoomy);
self.myShareImage = [ViewControllerFactoryyasuoCameraImage:tempImage];///这是为了分享用的。。。。。。
///添加touch事件
UITapGestureRecognizer *myTapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tapAction:)];
self.myImageV.userInteractionEnabled = YES;
myTapGesture.numberOfTapsRequired=2;//默认为1.表示点击的次数。
[self.myImageV addGestureRecognizer:myTapGesture];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
returnself.myImageV;
}
-(void)tapAction:(id)sender{
NSLog(@"轻拍,,,双击");
float minzoomx = self.myScrollView.frame.size.width / tempWidth;
float minzoomy = self.myScrollView.frame.size.height / tempHeight;
CGFloat zs = self.myScrollView.zoomScale;
zs = (zs == MIN(minzoomx, minzoomy)) ? 1.0 : MIN(minzoomx, minzoomy);
[UIViewbeginAnimations:nilcontext:NULL];
[UIViewsetAnimationDuration:0.6];
self.myScrollView.zoomScale = zs;
[UIViewcommitAnimations];
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
float minzoomx = self.myScrollView.frame.size.width / self.myImageV.size.width;
float minzoomy = self.myScrollView.frame.size.height / self.myImageV.size.height;
if(scrollView.zoomScale > MIN(minzoomx, minzoomy))
{
// [self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2)/minzoomx, (scrollView.frame.size.height / 2)/minzoomy)];
NSLog(@"上面。。。。。。。。。。。。。。。");
}else{
NSLog(@"下面。");
if (minzoomy>minzoomx) {
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2)/MIN(minzoomx, minzoomy), (scrollView.frame.size.height / 2))];
}else{
[self.myImageV setCenter:CGPointMake((scrollView.frame.size.width / 2), (scrollView.frame.size.height / 2)/MIN(minzoomx, minzoomy))];
}
}
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@end
相关推荐
本示例中,我们关注的是如何在ScrollView中实现一个功能:当用户下拉时,图片会放大,模拟微博封面图的效果。这种效果不仅提高了用户体验,也增加了应用的互动性。 首先,我们需要了解ScrollView的基本用法。...
本文将详细讲解如何在ScrollView中实现顶部使用ViewPager的轮播图,并且在下拉时图片能产生放大效果。这个功能的实现涉及到了Android的布局管理、动画效果以及自定义控件等多个知识点。 首先,我们来分析需求。标题...
这可以通过设置ImageView的ScaleType属性并监听点击和双击事件来实现。对于放大缩小,可以使用GestureDetector来识别用户的双击手势,当检测到双击时,调用ImageView的scale方法进行放大或缩小。 ```java class ...
当我们需要在ScrollView中显示一张大图,尤其是需要用户能够放大查看细节时,通常会将ImageView放入ScrollView中。ScrollView提供水平和垂直方向的滚动,ImageView则负责显示图片。 2. **ImageView的scaleType属性...
在实现"下拉图片放大"时,通常会在`ScrollView`内部嵌套一个`ImageView`来显示图片。 一、自定义`ScrollView` 为了实现下拉图片放大的功能,我们需要对默认的`ScrollView`进行扩展,创建一个自定义的`ScrollView`。...
在XML布局文件中,创建一个ScrollView,然后在ScrollView内嵌套一个LinearLayout或其他适合的布局,将需要放大的ImageView放在顶部。例如: ```xml <ScrollView android:layout_width="match_parent" android:...
通过实现UISCrollview 代理方法来实现图片的浏览,及放大缩小。 使用方法: viewWillAppear中实现 showbigImage=[[ShowBigImageBox alloc]init]; [showbigImage setShowBigImageBoxDelegate:self]; ...
当需要在ScrollView中实现图片的放大和缩小功能时,通常会结合ImageView和手势识别技术来完成。本篇文章将详细探讨如何在ScrollView中实现图片的Zoom功能。 首先,我们需要了解Android中的Zoom机制。在Android的...
在iOS应用开发中,用户经常会遇到需要点击图片后将其放大显示到全屏的需求,以便查看图像的细节。这个功能在照片浏览、电商商品展示、阅读应用等场景中非常常见。本篇文章将详细介绍如何在iOS中实现这个功能,主要...
为了实现下拉放大效果,我们需要监听scrollView的contentOffset属性,当用户向下滚动时,我们可以根据contentOffset的改变动态调整imageView的frame和transform属性,使其看起来像是被放大了。通常,我们会使用一个...
接下来,我们将在自定义ScrollView中添加一个ImageView,用于显示头部图片。为了实现图片的拉伸效果,我们可以利用`android.widget.ScaleImageView`,它允许图片根据视图大小进行缩放。在布局XML文件中,设置 ...
scrollView.addSubview(imageView) NSLayoutConstraint.activate([ imageView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), imageView.topAnchor.constraint(equalTo: scrollView.topAnchor), ...
2. **图片放大**:当图片被点击后,我们可以创建一个新的UIImageView(或者使用原来的ImageView,但设置其frame和contentMode适应放大后的大小),并将其添加到UIScrollView中。然后调整UIScrollView的contentSize以...
本教程将聚焦于一个常见的需求:如何实现点击图片后放大显示的功能。这在很多应用场景中都非常实用,如查看照片、产品详情等。下面我们将详细讨论这个功能的实现原理和步骤。 首先,我们要了解iOS中的UIImageView类...
在实现图片滑动和点击放大的功能时,我们可能需要对`ImageView`进行一些定制,比如设置其可触摸,以便监听用户的滑动和点击事件。 2. **手势识别**:Android提供了`GestureDetector`和`ScaleGestureDetector`类来...
在iOS开发中,图片预览是一项常见的功能,用于在用户点击图片时提供一个放大查看的界面。本项目是使用Swift语言实现的一个简单图片预览功能,特别加入了手势交互,包括捏合手势(pinch gesture)来实现图片的放大和...
在iOS应用开发中,"下拉图片放大"是一种常见的交互设计,主要应用于列表视图(UITableView)或滚动视图(UIScrollView)的头部。这种效果可以让用户在下拉刷新时,顶部的图片会随着手势的拉动而逐渐放大,既增加了...
综上所述,实现Android点击图片放大查看并带有缩放拖动功能,需要理解并运用ImageView的特性,手势检测,Matrix变换以及可能的自定义组件等技术。在实际开发中,还需要考虑性能优化和用户体验,确保应用的稳定性和...
在安卓应用开发中,实现图片左右滑动以及点击放大的功能是常见的用户界面交互设计,尤其是在展示图片细节或者浏览相册的应用中。这个压缩包文件“安卓开发-图片左右滑动 点击放大.zip.zip”可能包含了一个示例项目,...
为了实现头部ImageView的放大缩小效果,我们需要监听ScrollView的滑动事件。这可以通过重写`onScrollChanged`方法来实现: ```java @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {...