0

我已经在主 ViewController 中创建了一个表格视图,一旦我触摸到下一个视图控制器(DetailViewController)的行,它将显示菜肴的图像和名称。一旦我点击图像,它应该会变大,但事实并非如此越来越大。下面的代码是我在 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) 
 {
 }];
}
4

2 回答 2

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有一个很好的例子,它为 remove/addSubview 方法添加动画(不是帧修改):

[UIView transitionWithView:containerView
       duration:0.2
       options:UIViewAnimationOptionTransitionFlipFromLeft
       animations:^{
           [fromView removeFromSuperview];
           [containerView addSubview:toView];
       } completion:NULL];
于 2013-03-04T06:09:31.983 回答
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");
 }
于 2013-03-04T06:41:29.573 回答