我是iPhone開發的初學者,在我的應用程序中遇到UINavigationControoler問題。UINavigationController:在推送大圖像時轉換不平滑
我有一個UITableView中的主應用程序包(帶有縮略圖)的圖像列表,當選擇圖像時,UIScrollView視圖被推送到導航控制器。在使用大圖像時(例如使用iPhone相機拍攝的圖像),在推送過渡動畫期間會出現問題。它不光滑(低幀率),所以我想知道問題是什麼(+彈出過渡沒有問題)。下面是從圖像視圖我的代碼片段:
- (void)loadView
{
//consider loading in seperate thread?
//[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:[photo URL]];
UIImage *image = [UIImage imageNamed :[photo URL]];
imageView = [[UIImageView alloc] initWithImage:image];
UINavigationController *navController = [self navigationController];
//get navigation controller view frame
CGRect scrollViewSize = self.navigationController.view.frame;
//take navigation bar height into account for scroll view size
if(![navController isNavigationBarHidden]) {
scrollViewSize.size.height -= [[navController navigationBar] frame].size.height;
}
//take status bar height into account for scroll view size}
UIApplication *sharedApp = [UIApplication sharedApplication];
if(![sharedApp isStatusBarHidden]) {
scrollViewSize.size.height -= [sharedApp statusBarFrame].size.height;
}
//calculate minimum zoom scale
CGSize screenSize = scrollViewSize.size;
CGFloat widthRatio = screenSize.width/image.size.width;
CGFloat heightRatio = screenSize.height/image.size.height;
CGFloat initialZoom = (widthRatio > heightRatio) ? heightRatio : widthRatio;
//init scroll view
scrollView = [[PhotoScrollView alloc] initWithFrame:scrollViewSize];
[scrollView setMaximumZoomScale:1.0];
[scrollView setMinimumZoomScale:initialZoom];
[scrollView setBouncesZoom:YES];
[scrollView setContentSize :[image size]];
[scrollView setScrollEnabled :YES];
[scrollView setDelegate: self];
//imageView has to be added to scrollView in order for setZoomScale to work
[scrollView addSubview :imageView];
[scrollView setZoomScale:initialZoom];
imageDescription = [[UILabel alloc] initWithFrame:CGRectMake(0, (screenSize.height/2)-20, screenSize.width, 40)];
[imageDescription setText:[[self photo] getDetails]];
[imageDescription setFont:[UIFont systemFontOfSize:20]];
[imageDescription setTextAlignment:UITextAlignmentCenter];
[imageDescription setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
[imageDescription setAlpha:0];
[image release];
[super loadView];
}
- (void)viewDidLoad
{
[self.view addSubview :scrollView];
[self.view addSubview:imageDescription];
[super viewDidLoad];
}
我已經嘗試過在單獨的線程加載圖像([NSThread detachNewThreadSelector:@選擇(的LoadImage :) toTarget:自withObject:照片URL]),但它確實沒有幫助。我需要調整圖像大小嗎?另外我想知道如何編寫默認的iPhone應用程序照片,因爲它具有類似的功能,但在轉換過程中圖像模糊不清。
謝謝,我看了視頻,這正是我需要的:) –