2012-05-30 115 views
1

我有一个UIView,我想在用户点击它时自动缩放成屏幕大小。为什么我的视图在旋转90度之前旋转?

我把代码http://cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html

和变焦的作品,除变焦开始视图旋转90度之前。为什么会发生?

(该视图是一个传送带内。到用户敲击视图之前,装置被旋转到景观,在该点的转盘视图控制器被压入导航堆栈和显示的转盘。)

的代码是:

- (void)buttonTapped:(UIButton *) sender 
{ 
    NSInteger index = [self.carousel indexOfItemView:sender]; 

    UIView *currentView = [self.carousel itemViewAtIndex: index]; 
    UIView *proxyView = [[UIView alloc] initWithFrame:currentView.frame]; 
    proxyView.hidden = YES; 
    proxyView.autoresizingMask = currentView.autoresizingMask; 
    [currentView.superview addSubview: proxyView]; 

    CGRect frame = [currentView.window convertRect:currentView.frame fromView:proxyView.superview]; 
    [currentView.window addSubview:currentView]; 
    currentView.frame = frame; 

    [UIView 
    animateWithDuration:2.4 
    animations:^{ 
     currentView.frame = currentView.window.bounds; 
    }]; 

(圆盘传送带是一个UIView派生对象,从https://github.com/nicklockwood/iCarousel

由于

回答

0

我怀疑,这个问题可以是:

currentView.frame = frame; 

或:

currentView.frame = currentView.window.bounds; 

在横向模式下,您的看法或封闭意见一个具有变换一切旋转90°。如UIView docs indicate,frame属性未定义,如果视图的transform属性是标识转换以外的任何属性。这可能是设置您的视图的frame隐式设置其transform回到身份,这会导致它回到纵向方向。

在上述两个链接的文档警告反对改变frame时,有一个转换,并提供一个解决方案:

更改这个属性可以是动画。但是,如果变换 属性包含非标识转换,则框架 属性的值未定义,因此不应修改。在这种情况下, 可以使用中心属性重新定位视图,并使用bounds属性调整大小 。

+0

如果我注释掉的第一行,视图跳转到左下角(这是在中心),然后旋转。如果我注释掉第二行,它保持居中,但仍然旋转(但当然不会缩放)。 – Gruntcakes

+0

@ ChrisP.Bacon解决方案,如文档中所解释的,如果存在非标识转换,则为“bounds”和“center”而不是“frame”制作动画。 – Caleb

+0

旋转发生在动物之前,所以如果我完全注释掉动画代码,那么旋转仍然会发生。 – Gruntcakes