2013-06-05 124 views
0

我是xcode和objective c的新手,我想知道如何使用輕擊手勢使圖像全屏觸摸... 任何人都可以幫助我?如何在iOS應用程序中使圖像變成全屏應用程序

這裏是我試過的代碼:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; 
tap.numberOfTapsRequired = 1; 
tap.cancelsTouchesInView = NO; 
imageView.userInteractionEnabled = YES; 
[imageView addGestureRecognizer:tap]; 
} 

-(void)handleTap{ 
imageView.frame=CGRectMake(0,0,320,480); 

} 
+0

檢查:-http://stackoverflow.com/questions/9008975/how-to-tap-to-zoom-and-double-tap-to-zoom-out-with-uiscrollview –

+1

不忘記imageView.contentMode = UIViewContentModeScaleToFill; –

回答

0

你可以改變ImageView的的幀的大小it'l自動進入全屏模式。

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)]; 
tapGesture.numberOfTapsRequired=1; 
[imageView setUserInteractionEnabled:YES]; 
[imageView addGestureRecognizer:tapGesture]; 

-(void)handleTapGesture{ 
    imageView.frame=CGRectMake(0,0,320,480); 

} 
+0

我剛收到此錯誤消息: @autoreleasepool { return UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class])); – Delete

+0

你是否保留這段代碼? – 2013-06-05 11:23:58

+0

我把它放在ViewDidLoad下面[super viewDidLoad] – Delete

0

// Detecting touches on your UIImageView 
UITapGestureRecognizer *myImageViewTapped = [[UITapGestureRecognizer alloc] initWithTarget:self 
                       action:@selector(changeFrameOfMyImage)]; 

myImageViewTapped.cancelsTouchesInView = NO; 
[self.view addGestureRecognizer:myImageViewTapped]; 

//... 
//... 

-(void)changeFrameOfMyImage { 
    myImageView.frame = self.view.frame; 
} 

可能會做的伎倆!

0
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; 
    tapGesture.numberOfTapsRequired = 1; 
    tapGesture.cancelsTouchesInView = NO; 
    imageView.userInteractionEnabled = YES; 
    [imageView addGestureRecognizer:tapGesture]; 

    -(void)handleTemplateTap:(UIGestureRecognizer *)sender 
    { 
     imageview.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height); 
    } 
+0

謝謝!我要在哪裏放什麼?我要在.h文件中寫什麼? – Delete