ios下方滑出视图

本文介绍了如何使用Objective-C在iOS应用中实现视图的滑动动画效果,包括滑动进入和滑动退出两个过程。通过调整视图的位置来创建动画,并在动画结束后移除视图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-(void) slideIn {
    CGRect frame = self.slideView.frame;
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
    self.slideView.frame = frame;
    [self.view addSubview:self.slideView];
    [UIView beginAnimations:nil context:nil];
    
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height - self.slideView.bounds.size.height);
    self.slideView.frame = frame;
    [UIView commitAnimations];
}

- (void) slideOut {
    
    [UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];
    
    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    
    // Move this view to bottom of superview
    CGRect frame = self.slideView.frame;
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
    self.slideView.frame = frame;
    
    [UIView commitAnimations]; 
}

// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [slideView removeFromSuperview];
    }
}

转载于:https://www.cnblogs.com/loveyy/archive/2012/07/04/2576398.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值