在ipad上将图像切换为全屏
在ipad上完成此任务我遇到了很多麻烦:当图像上的双重磁带将此图像切换到全屏时,再次双击时会回到原始显示,同样使用捏合。我正在使用
UIGestureRecognizer
尝试这样做。谢谢你的帮助。
GesturesViewController.h
#import <UIKit/UIKit.h>
@interface GesturesViewController : UIViewController
<UIActionSheetDelegate>{
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UIImageView *imageView;
@end
GesturesViewController.m
#import "GesturesViewController.h"
#import "GesturesAppDelegate.h"
@implementation GesturesViewController
@synthesize imageView;
CGRect originalFrame,fullScreenFrame;
BOOL isFullScreenMode;
- (void)viewDidLoad {
// Loading test image
imageView.image = [UIImage imageNamed:@"image1.jpg"];
//---tap gesture---
isFullScreenMode = NO;
originalFrame = CGRectMake(imageView.frame.origin.x,imageView.frame.origin.y,imageView.frame.size.width,imageView.frame.size.height);
//changes
fullScreenFrame = CGRectMake(0,0,768,1004);
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
//---pinch gesture---
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[imageView addGestureRecognizer:pinchGesture];
[pinchGesture release];
[super viewDidLoad];
}
//---handle tap gesture---
-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
// HOW TO ACCOMPLISH THIS PART
if (isFullScreenMode)
[imageView setFrame:originalFrame];
else
[imageView setFrame:fullScreenFrame];
[imageView setCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)];
isFullScreenMode = !isFullScreenMode;
NSLog(@"Image View : %@",imageView);
}
//---handle pinch gesture---
-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
if (sender.state == UIGestureRecognizerStateEnded){
// HOW TO ACCOMPLISH THIS ---
if (factor > 1 && !isFullScreenMode) {
//---pinching in---
[imageView setFrame:fullScreenFrame];
} else {
//---pinching out---
[imageView setFrame:originalFrame];
}
isFullScreenMode = !isFullScreenMode;
[imageView setCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)];
}
NSLog(@"Image View : %@",imageView);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[images release];
[imageView release];
[super dealloc];
}
@end
谢谢。
没有找到相关结果
已邀请:
4 个回复
徐百晴墓斜
我只选择了代码的必要部分......来自
.... 如果你看到我们之前讨论的相同.....但几乎没有改进.......
犁攀富
谢谢,
抽法
要么
appDelegate&lt; -----获取appdelegate对象的实例,以便我们可以检索窗口对象.......
// **在事件中只设置imageView的框架 - 用于了解当前状态 - 无论是fullScreen还是原始框架我们需要有一个标志........它应该是全局的...... 所以宣布一个全球旗帜....
并将其初始化为
in
在手势动作中只需检查此标志并写下以下内容......
长拳