ios – UIView分为两部分动画

前端之家收集整理的这篇文章主要介绍了ios – UIView分为两部分动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在和UIView合作.我想在那个视图上做动画.点击视图时,应将其分为两部分并向两侧移动.请帮我解决一个问题.

解决方法

@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.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类.

猜你在找的iOS相关文章