在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
谢谢。     
已邀请:
- (void)toggleZoom:(UITapGestureRecognizer *)gestureRecognizer
{
    if (proxyView)
    {
        CGRect frame =
            [proxyView.superview
                convertRect:self.view.frame
                fromView:self.view.window];
        self.view.frame = frame;

        CGRect proxyViewFrame = proxyView.frame;

        [proxyView.superview addSubview:self.view];
        [proxyView removeFromSuperview];
        [proxyView autorelease];
        proxyView = nil;
        self.view.frame = proxyViewFrame;

    }
    else
    {
        proxyView = [[UIView alloc] initWithFrame:self.view.frame];
        proxyView.hidden = YES;
        proxyView.autoresizingMask = self.view.autoresizingMask;
        [self.view.superview addSubview:proxyView];

        CGRect frame =
            [self.view.window
                convertRect:self.view.frame
                fromView:proxyView.superview];
        [self.view.window addSubview:self.view];
        self.view.frame = frame;
        self.view.frame = self.view.window.bounds;

    }


}
我只选择了代码的必要部分......来自
ZoomingViewController
.... 如果你看到我们之前讨论的相同.....但几乎没有改进.......     
为此,您必须首先将原始帧大小存储在全局某处,以便以后可以重新进行。
you need create two global frames

    CGRect originalFrame, fullScreenFrame;

    //in viewDidLoad initialize these frames... originalFrame with imageView frame and 
fullScreenFrame with the iPad window coordinates........ but remeber this can distort the
 aspect ratio so just calculate the aspect ratio of original image by using its height and
 width and accordingly create the full screen frame for the image....... 

    and just assign these frames in your gesture action.
谢谢,     
viewDidLoad
originalFrame = imageView.frame;
要么
originalFrame = CGRectMake(imageView.frame.origin.x,imageView.frame.origin.y,imageView.frame.size.width,imageView.frame.size.height);
appDelegate&lt; -----获取appdelegate对象的实例,以便我们可以检索窗口对象.......
UIWindow *tempWindow = [appDelegate window];
fullScreenFrame = CGRectMake(tempWindow .frame.origin.x,tempWindow .frame.origin.y,tempWindow .frame.size.width,tempWindow.frame.size.height);
// **在事件中只设置imageView的框架 - 用于了解当前状态 - 无论是fullScreen还是原始框架我们需要有一个标志........它应该是全局的...... 所以宣布一个全球旗帜....
BOOL isFullScreenMode
并将其初始化为
NO
in
viewDidLoad
isFullScreenMode = NO;
在手势动作中只需检查此标志并写下以下内容......
if (isFullScreenMode)
        [imageView setFrame:originalFrame];
else
       [imageView setFrame:fullScreenFrame];

isFullScreenMode = !isFullScreenMode;
    
@implementation ImageFullScreen
@synthesize myImage;

#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);
}
    

要回复问题请先登录注册