我正在使用UICollectionView,並且通過繼承該類定義了一個自定義的UICollectionViewCell。類的初始化定義了兩個視圖,只是這樣的:超級視圖旋轉後UIButton沒有收到觸摸
[[NSBundle mainBundle] loadNibNamed:@"ProtelViewCellFlipped" owner:self options:nil];
CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
[flippedView.layer setTransform:transform];
[flippedView setHidden:YES];
[self addSubview:flippedView];
[[NSBundle mainBundle] loadNibNamed:@"ProtelViewCell" owner:self options:nil];
[self addSubview:selfView];
[selfView.layer setZPosition:1];
其中flippedView是由「ProtelViewCellFlipped」 XIB文件中定義的圖,selfView處於「ProtelViewCell」 XIB文件中定義的圖。視圖層次結構是這樣的:the view hierarchy http://massimomarra.altervista.org/gerarchia.png
的事情是,所述翻轉視圖旋轉(就好像它是「selfView」視圖的另一側)由CATransform3D
,然後它被隱藏。這是好的,它的工作原理。
該selfView
視圖上有一個UIButton。在視圖的右下角。如果我按下該按鈕,則會觸發此方法:
- (void)infoButtonPressed:(UIButton *)sender
{
NSString *animationKey = (selfView.layer.zPosition > flippedView.layer.zPosition)? @"forward" : @"backwards";
CGFloat animationDuration = 0.3;
if (selfView.layer.zPosition > flippedView.layer.zPosition)
[self.layer removeAllAnimations];
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
[rotation setValue:animationKey forKey:@"id"];
rotation.toValue = [NSNumber numberWithFloat:M_PI];
rotation.duration = animationDuration;
rotation.removedOnCompletion = NO;
rotation.fillMode = kCAFillModeForwards;
[self.layer addAnimation:rotation forKey:animationKey];
[self performSelector:@selector(flipLayers) withObject:nil afterDelay:animationDuration/2];
}
使self
視圖與動畫一起旋轉。另外,在動畫過程中被調用此方法:
- (void)flipLayers
{
[selfView setHidden:!selfView.hidden];
[flippedView setHidden:!selfView.hidden];
[selfView.layer setZPosition:flippedView.layer.zPosition];
[flippedView.layer setZPosition:(1-selfView.layer.zPosition)];
}
使得flippedView
變得可見(和selfView
隱藏),而他的層的z向位置變得高於selfView
。
所以現在我有flippedView
可見,並且它顯示正確。它也有一個按鈕,但要觸發他的動作,我必須點擊另一個位置:flipped view scheme: i have to tap where the button "was" before the rotation http://massimomarra.altervista.org/s03KRJAUk7C_nP3yTXb7TBQ.png
看起來旋轉只是修改視圖的圖形,而不是內容。 你能幫我嗎?
感謝大家提前!