2012-01-09 15 views
4

私はUIViewを使用しています。私はその視点でアニメーションをしたい。ビューをクリックしながら、2つの部分に分けて両側に移動する必要があります。適切な解決策で私を助けてください。UIViewはアニメーションで2つの部分に分割されます

+0

ちょっと正確に何をしたいのですか? – mashios

+0

オープニングドアと同じですか? – Cyrille

+0

UIViewに画像付きのCALayersが含まれています。ビューをクリックしている間は、2つに移動してアニメーションで消える必要があります。次に、他のいくつかの画像と同じビューがアニメーションで表示されます。 – Rose

答えて

1
@implementation SplitView 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
    // Initialization code 
     self.backgroundColor = [UIColor blueColor]; 

     UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(split)]; 
     [self addGestureRecognizer:ges]; 
     [ges release]; 
    } 
    return self; 
} 
- (void)split { 
    CGRect f = self.frame; 
    CGRect f1 = CGRectMake(CGRectGetMinX(f), f.origin.y, f.size.width/2, f.size.height); 
    CGRect f2 = CGRectMake(CGRectGetMidX(f), f.origin.y, f.size.width/2, f.size.height); 

    SplitView *view1 = [[[SplitView alloc] initWithFrame:f1] autorelease]; 
    [self.superview addSubview:view1]; 

    SplitView *view2 = [[[SplitView alloc] initWithFrame:f2] autorelease]; 
    [self.superview addSubview:view2]; 

    f1.origin.x -= 30; 
    f2.origin.x += 30; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    view1.frame = f1; 
    view2.frame = f2; 
    [UIView commitAnimations]; 

    [self removeFromSuperview]; 
} 

@end 

なUIViewクラスを作成してください。

関連する問題