0
我想在TTScrollView
中顯示一些TTImageView
。TTImageView問題
- (UIView*)scrollView:(TTScrollView*)scrollView pageAtIndex:(NSInteger)pageIndex {
TTView* pageView = nil;
if (!pageView) {
pageView = [[[TTView alloc] init] autorelease];
pageView.backgroundColor = [UIColor clearColor];
pageView.userInteractionEnabled = NO;
}
NSString *imagePath = [self.screenShotImgPath objectAtIndex:pageIndex];
TTImageView *imageView = [[[TTImageView alloc] initWithFrame:CGRectZero] autorelease];
imageView.autoresizesToImage = YES;
imageView.urlPath = imagePath;
imageView.backgroundColor = [UIColor clearColor];
imageView.delegate = self;
//here I need to rotate image
if (imageView.width > imageView.height){
CGAffineTransform tran = CGAffineTransformIdentity;
CGSize bnds = imageView.size;
CGSize bnds2 = imageView.size;
bnds = [self swapWidthAndHeight:bnds];
tran = CGAffineTransformMakeTranslation(0.0,bnds2.width);
tran = CGAffineTransformRotate(tran, [self degreesToRadians:-90.0]);
imageView.transform = tran;
}
//here I need to scale image view frame to fit image actual scale
CGFloat scale = imageView.width/imageView.height;
CGFloat scaledWidth = (scrollView.height - 20.f) * scale;
imageView.frame = CGRectMake((scrollView.width - scaledWidth)/2, 10.f, scaledWidth, scrollView.height - 20.f);
[pageView addSubview:imageView];
return pageView;
}
但有一個問題:TTImageView
異步下載圖像。所以這是退出可能,當代碼去
if (imageView.width > imageView.height){
此行圖像未加載。所以拋出異常。
由於圖像視圖在
- (UIView*)scrollView:(TTScrollView*)scrollView pageAtIndex:(NSInteger)pageIndex {
添加,所以我不能移動下面的代碼旋轉出這個方法
if (imageView.width > imageView.height){
CGAffineTransform tran = CGAffineTransformIdentity;
CGSize bnds = imageView.size;
CGSize bnds2 = imageView.size;
bnds = [self swapWidthAndHeight:bnds];
tran = CGAffineTransformMakeTranslation(0.0,bnds2.width);
tran = CGAffineTransformRotate(tran, [self degreesToRadians:-90.0]);
imageView.transform = tran;
}
我能做些什麼來solove這個問題的?
哈哈,@Luda幾乎是一年前的事,但想感謝你給我的方法〜漂亮〜! –