iPhone:在 UITableViewCell 内旋转滚动视图

发布于 2024-11-30 02:20:12 字数 1275 浏览 0 评论 0原文

我将 shouldAutorotateToInterfaceOrientation 函数发送到我创建此函数的自定义 UITableViewCell,因此我想在该单元格内旋转滚动视图。

但我尝试的一切都没有显示任何反应。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    NSLog(@"rotate cell");
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){

        NSLog(@"left");
    }
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){

        NSLog(@"right");
    }

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];

    // (180 * M_PI) / 180 == M_PI, so just use M_PI
    imagescroll.transform = CGAffineTransformMakeRotation(M_PI);

    [UIView commitAnimations];

    NSLog(@"rotation should start but doesnt");
}



return (interfaceOrientation == UIInterfaceOrientationPortrait);

是否

需要重新渲染单元格或其他内容?


很抱歉造成误解。

在 UITableViewController 上,我重写 shouldAutoRotate 函数并向表格内的所有单元格发送函数调用。 TableViewController 不允许旋转,并且从他自己的函数中仅发送“否”返回。 但所有单元格都可以执行某些操作,其中一个单元格应该旋转其 uiScrollView。呼叫到达单元格,NSLog 根据我的旋转向左或向右输出。但 Scrollview 没有做任何事情。

i send the shouldAutorotateToInterfaceOrientation Funktion to the custom UITableViewCell where i created this function and so i want to rotate a scrollview inside this Cell.

But everything i tryed doesn't show any reaction.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    NSLog(@"rotate cell");
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){

        NSLog(@"left");
    }
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){

        NSLog(@"right");
    }

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];

    // (180 * M_PI) / 180 == M_PI, so just use M_PI
    imagescroll.transform = CGAffineTransformMakeRotation(M_PI);

    [UIView commitAnimations];

    NSLog(@"rotation should start but doesnt");
}



return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

is there a need for rerendering the cell or something else?


sorry for the misunderstandings.

On the UITableViewController i override the shouldAutoRotate function and send a function call to all cells inside the table. The TableViewController is not allowed to rotate and sends from his own function just a NO back.
But all of the Cells can do something and one of them should rotate its uiScrollView. The Call comes to the cell and the NSLog comes out with left or right based on my rotation. But the Scrollview doent do anything.

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

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

发布评论

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

评论(2

眼中杀气 2024-12-07 02:20:12

您能多解释一下您想要实现的目标吗?看起来有点困惑,在 UIViewController 中重写了 shouldAutorotate 方法,让操作系统知道允许什么方向。然后,您可以重写 willAutorotate 和 didAutorotate 方法来捕获这些特定操作。也就是说,如果您正确设置视图属性,则大部分都是不必要的(即,如果主视图旋转,您的子视图也会旋转)。

如果您添加更多详细信息作为评论,我将用更多相关内容更新此答案。

问候

戴夫

Can you explain a little more about what you are trying to achieve? It seems a little confused, shouldAutorotate method is overridden in the UIViewController to let the OS know what orientations are allowed. You then override the willAutorotate and didAutorotate methods to trap these specific actions. That said, most of this is unnecessary if you set the view properties correctly (i.e., your subViews will also rotate if the main view does).

If you add a little more detail as a comment, I'll update this answer with more relevant stuff.

Regards

Dave

渡你暖光 2024-12-07 02:20:12

shouldAutorotateToInterfaceOrientation: 方法并不意味着执行实际的旋转。这不是 UIViewUITableViewCell 的方法,而是 UIViewController 的方法。 UIViewController 的子类可以重写此方法来指示当前视图控制器支持的方向。

覆盖您用来显示表格的视图控制器中的该方法,并为支持的方向返回 YES,并且旋转将自动为您完成。然后您所要做的就是确保在视图控制器中设置视图的 autoresizingMask ,以确保它们相应地拉伸或收缩。

如果您想实现其他目标,请添加更多详细信息作为您想要做的事情。即界面更改期间的自定义动画,根据方向等显示不同的视图或控件。

The shouldAutorotateToInterfaceOrientation: method is not meant to do the actual rotation. This is not a method of UIView or UITableViewCell, but of UIViewController. Subclasses of UIViewController can override this method to indicate what orientations the current view controller supports.

Override that method in the view controller that you are using to display the table and return YES for supported orientations and the rotation will be done for you automatically. Then all you have to do is make sure you set the autoresizingMask of the views in your view controller to make sure they stretch or shrink accordingly.

If you are trying to achieve something else, please add more details as what you are trying to do. i.e. custom animation during an interface change, show different views or controls depending on the orientation, etc.

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