iOS 点击button 弹出 View 怎么设置从下往上 弹出的动画
1个回答
展开全部
//这里关键的地方是把view的y坐标设到屏幕下方
/** objective-c代码*/
let aView = UIView.init();
let yOffset = UIScreen.main().bounds.height;
let yTargetOffset = 200; //你想要最终放置的y坐标
let originalRect = CGRect.init(x: 0, y: yOffset, width: 100, height: 200);
let targetRect = CGRect.init(x: 0, y: yTargetOffset, width: 100, height: 200);
//初始位置
aView.frame = originalRect;
//动画
UIView.animate(withDuration: 0.3) {
//赋值最终位置
aView.frame = targetRect;
}
/** oc代码*/
UIView *aView = [UIView new];
CGFloat yOffset = [UIScreen mainScreen].bounds.size.height; //初始y值
CGFloat yTargetOffset = 200; //目标y值
CGRect originalRect = CGRectMake(0, yOffset, 100, 200);
CGRect targetRect = CGRectMake(0, yTargetOffset, 100, 200);
//初始位置
aView.frame = originalRect;
//动画
[UIView animateWithDuration:.3 animations:^{
aView.frame = targetRect;
}];
/** objective-c代码*/
let aView = UIView.init();
let yOffset = UIScreen.main().bounds.height;
let yTargetOffset = 200; //你想要最终放置的y坐标
let originalRect = CGRect.init(x: 0, y: yOffset, width: 100, height: 200);
let targetRect = CGRect.init(x: 0, y: yTargetOffset, width: 100, height: 200);
//初始位置
aView.frame = originalRect;
//动画
UIView.animate(withDuration: 0.3) {
//赋值最终位置
aView.frame = targetRect;
}
/** oc代码*/
UIView *aView = [UIView new];
CGFloat yOffset = [UIScreen mainScreen].bounds.size.height; //初始y值
CGFloat yTargetOffset = 200; //目标y值
CGRect originalRect = CGRectMake(0, yOffset, 100, 200);
CGRect targetRect = CGRectMake(0, yTargetOffset, 100, 200);
//初始位置
aView.frame = originalRect;
//动画
[UIView animateWithDuration:.3 animations:^{
aView.frame = targetRect;
}];
追答
写错了,上面是swift
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询