iPhone:在UITableViewCell中旋转Scrollview

时间:2011-08-17 15:11:47

标签: iphone objective-c xcode uitableview rotation

我将shouldAutorotateToInterfaceOrientation Funktion发送到我创建此功能的自定义UITableViewCell,因此我想在此Cell内旋转scrollview。

但我尝试的一切都没有表现出任何反应。

- (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不允许旋转,并从他自己的函数发送一个NO返回。 但是所有的Cell都可以做一些事情,其中​​一个应该旋转它的uiScrollView。呼叫进入单元格,NSLog根据我的旋转向左或向右输出。但Scrollview会做任何事情。

2 个答案:

答案 0 :(得分:1)

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

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

此致

戴夫

答案 1 :(得分:1)

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

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

如果您正在尝试实现其他目标,请添加更多详细信息,告诉您要执行的操作。即界面更改期间的自定义动画,根据方向等显示不同的视图或控件。