[英]Passing UIImage to second view controller lags transition
I'm using a UIImagePickerController to select an image from my photo album. 我正在使用UIImagePickerController从我的相册中选择图像。 Once I've selected the image, I'm passing the image through to a second view controller and displaying it in a UIImageView.
选择图像后,将图像传递给第二个视图控制器,并将其显示在UIImageView中。 See code below:
参见下面的代码:
First view controller: 第一视图控制器:
- (IBAction)selectPhoto
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:self.imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:@"UploadViewController" bundle:nil];
[uploadViewController setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
[picker pushViewController:uploadViewController animated:YES];
}
Second view controller: 第二个视图控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the image view image
imageView.image = self.image;
}
The code does the job, however, when I push from the image picker to my second view controller, it lags as it's transitioning. 代码可以完成工作,但是,当我从图像选择器推入第二个视图控制器时,它在过渡时会滞后。
Ideally I would like a smooth transition but I would be happy if it just waited half a second or something and then moves smoothly. 理想情况下,我希望平稳过渡,但是如果它只等了半秒钟或之后才平稳运行,我会很高兴。
Can any explain why this could be happening and how/if I can get around it? 有谁能解释为什么会发生这种情况以及如何/如果能够解决这个问题?
Thanks. 谢谢。
延迟可能来自渲染图像,您可以尝试让UploadViewController的初始视图包含活动微调器,然后实际上在viewDidAppear方法中设置图像,该方法应在动画完成后调用。
Try with this , here timer is introduced in order to provide delay(0.5sec) , 尝试一下,这里引入计时器是为了提供delay(0.5sec),
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[NSTimerscheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerAction:) userInfo:info repeats:NO];
}
-(void)timerAction:(NSTimer *)timer
{
UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:@"UploadViewController" bundle:nil];
[uploadViewController setImage:[[timer userInfo]objectForKey:@"UIImagePickerControllerOriginalImage"]];
[picker pushViewController:uploadViewController animated:YES];
[uploadViewController release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.