【发布时间】:2011-05-12 12:04:15
【问题描述】:
我遇到了和HERE一样的问题..请帮忙!
我有一个 UIViewController 支持滚动和缩放 图像视图。效果很好。
我正在尝试添加对更改的支持 在方向。由于种种原因,我 需要通过旋转来做到这一点 UIImageView 而不是 界面视图控制器。
我可以进行图像旋转,但是 如果用户在图像时捏合缩放 旋转,图像的大小和 位置变得疯狂(例如,图像 跳到一边,变得太小, 似乎不知道范围在哪里 的滚动视图是等)。
h文件核心内容:
@interface ImageViewController : UIViewController <UIScrollViewDelegate>
{
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *imageView;
}
@property (nonatomic, assign) UIScrollView *scrollView;
@property (nonatomic, assign) UIImageView *imageView;
@end
支持缩放:
-(UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
}
支持滚动(设置在 图片已加载):
[scrollView setContentSize: CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height)];
支持旋转图片时 方向变化:
-(void)orientationChanged:(NSNotification *)note
{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
CGFloat angle = 0;
switch (orientation)
{
case UIDeviceOrientationLandscapeLeft:
angle = M_PI/2.0f;
break;
case UIDeviceOrientationLandscapeRight:
angle = -M_PI/2.0f;
break;
case UIDeviceOrientationPortraitUpsideDown:
angle = M_PI;
break;
default:
break;
}
self.imageView.transform = CGAffineTransformMakeRotation(angle);
}
我怀疑问题在于 scrollView 很困惑,因为 图像的大小已更改,因为 旋转,但我对此一无所知 如何解决它。有任何想法吗? FWIW, 如果我改变缩放确实有效 方向,然后再改回来 在缩放之前“垂直”。
【问题讨论】:
-
尝试在这里详细说明以获得答案。我已经编辑了你原来的帖子。从链接复制粘贴。
标签: iphone uiscrollview uiimageview orientation