当图像在 UIScrollView 内旋转时保持缩放比例

发布于 2024-11-14 01:17:33 字数 983 浏览 3 评论 0原文

我在 ScrollView 中有一个图像。它允许捏合和缩放。还可以将 ScrollView 内的图像旋转到自定义角度。当我这样做时,我会丢失图像的当前缩放级别,并且它会恢复到 100% 缩放并旋转。有没有办法在旋转图像时保持缩放级别?

我现在正在这样做:

    UIScrollView* mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 80, 
                            self.view.frame.size.width, self.view.frame.size.height   )];

   self.pictureView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Image1.png"]];

    [mainScrollView setContentSize:CGSizeMake//(620,612)];
     (self.pictureView.frame.size.width, self.pictureView.frame.size.height)];
    [mainScrollView addSubview:self.pictureView];
    mainScrollView.minimumZoomScale = 0.5;
    mainScrollView.maximumZoomScale = 6.0;
    mainScrollView.delegate = self;   
    [mainScrollView setScrollEnabled:YES];
    [self.view addSubview:mainScrollView];
    [mainScrollView release];


-(void) rotatePicture:(float) value{
 self.pictureView.transform = CGAffineTransformMakeRotation(value );
}

I have an image inside a ScrollView. It allows for pinch and zoom. It is also possible to rotate the image inside the ScrollView to a custom degree. When I do that, I lose the current zoom level of the image, and it reverts back to its 100% zoom and rotates. Is there a way I can maintain the zoom level while rotating the image?

I am doing this at the moment:

    UIScrollView* mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 80, 
                            self.view.frame.size.width, self.view.frame.size.height   )];

   self.pictureView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Image1.png"]];

    [mainScrollView setContentSize:CGSizeMake//(620,612)];
     (self.pictureView.frame.size.width, self.pictureView.frame.size.height)];
    [mainScrollView addSubview:self.pictureView];
    mainScrollView.minimumZoomScale = 0.5;
    mainScrollView.maximumZoomScale = 6.0;
    mainScrollView.delegate = self;   
    [mainScrollView setScrollEnabled:YES];
    [self.view addSubview:mainScrollView];
    [mainScrollView release];


-(void) rotatePicture:(float) value{
 self.pictureView.transform = CGAffineTransformMakeRotation(value );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间海 2024-11-21 01:17:33

您尝试过吗:

-(void) rotatePicture:(float) value{
     self.pictureView.transform = CGAffineTransform CGAffineTransformRotate (self.pictureView.transform, value);
}

它的作用是保留图片视图上的缩放变换,并在其顶部添加旋转。

Did you try:

-(void) rotatePicture:(float) value{
     self.pictureView.transform = CGAffineTransform CGAffineTransformRotate (self.pictureView.transform, value);
}

What this does is to preserve the zoom transform on the pictureView, and adds a rotate on top of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文