2013-03-04 37 views
0

我在主ViewController中創建了一個表視圖,一旦我觸摸它將要到下一個視圖控制器(DetailViewController)的行,它將顯示圖像和菜名。一旦我點擊圖像它應該變大,但它不會變得更大。下面的代碼是我在DetailViewController中試過的。如何在UITextView中調整圖像並點擊以變大

DetailViewController.m

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10,100, 100)]; 
CGRect textViewFrame = CGRectMake(10, 10, 300, 400); 
textView = [[UITextView alloc] initWithFrame:textViewFrame]; 
textView.returnKeyType = UIReturnKeyDone; 
textView.backgroundColor=[UIColor whiteColor]; 
textView.editable=NO; 
textView.delegate = self; 
[self.view addSubview:textView]; 
[textView addSubview:imageView]; 
textView.alpha = 0.9; 
textView.font = [UIFont systemFontOfSize:15]; 

if(mrowno==0) 
{ 
    imageView.image=[UIImage imageNamed:@"Dosa.jpg"]; 
    textView.text = @"\n\n\n\n\n\n\n\nDOSA\nDosa, "; 
    imageButton = [[UIButton alloc]init]; 
    [imageButton setFrame:CGRectMake(0, 0, 100, 100)]; 
    [imageButton addTarget:self action:@selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    [imageView addSubview:imageButton]; 

} 

這裏是使圖像變大

-(void)imageTapped:(UIButton*)in_sender 
{ 


[UIView transitionWithView:in_sender.superview duration:0.8f options:UIViewAnimationOptionCurveLinear animations:^ 
{ 
    [in_sender.superview setFrame:CGRectMake(0, 0, 300, 500)]; 
} 
       completion:^(BOOL finished) 
{ 
}]; 
} 

回答

0

可以增加,並通過夾送在降低圖像的大小和尖滅,如果需要

-(void)viewDidLoad 
{ 
UIPinchGestureRecognizer* pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self   action:@selector(pinching:)]; 
[self.imageView addGestureRecognizer:pinch]; 
    } 

-(void)pinching:(UIGestureRecognizer*) recognizer 
{ 
UIPinchGestureRecognizer* pinch=(UIPinchGestureRecognizer*) recognizer; 
self.imageView.transform=CGAffineTransformScale(self.imageView.transform, pinch.scale, pinch.scale); 
pinch.scale=1; 
NSLog(@"pinching"); 
} 
+0

我已經嘗試過與你的代碼仍然不工作。 – lreddy 2013-03-04 07:01:27

0

你不想使用transitionWithView的方法。相反,你要使用+ animateWithDuration: delay:options:animations:completion:(或任何其較短的變體...)

[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
    viewYouWantToAnimate.frame = CGRectMake(..., ..., ..., ...); 
} completion:^{ 
    //Add completion code here, or pass nil if you don't have anything to do. 
}]; 

編輯:如果您想知道transitionWithView用什麼...在AppleDocs有它添加動畫的一個很好的例子用於移除/ addSubview方法(不是幀的修改):

[UIView transitionWithView:containerView 
     duration:0.2 
     options:UIViewAnimationOptionTransitionFlipFromLeft 
     animations:^{ 
      [fromView removeFromSuperview]; 
      [containerView addSubview:toView]; 
     } completion:NULL];