我想要一个 UIView 在平移手势上拖动到屏幕底部,但当它到达屏幕底部时,视图 alpha 应该缩小到“零”。
反之亦然,当我向上拖动视图时,UIView alpha 应缩小到“1”
但问题是视图的 Alpha 缩小到“零”平移一半屏幕时或有时当我缓慢拖动视图时。
最初我将 UIView 背景颜色设置为黑色。
我需要逐渐缩小视图的 alpha,任何想法或建议都会有帮助。
UIPanGestureRecognizer * panner = nil;
panner = [[UIPanGestureRecognizer alloc] initWithTarget: self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panner ];
[panner setDelegate:self];
[panner release];
CGRect frame = CGRectMake(0, 0, 320, 460);
self.dimmer = [[UIView alloc] initWithFrame:frame];
[self.dimmer setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dimmer];
-(IBAction) handlePanGesture:(UIPanGestureRecognizer *) sender {
static CGPoint lastPosition = {0};
CGPoint nowPosition; float alpha = 0.0;
float new_alpha = 0.0;
nowPosition = [sender translationInView: [self view]];
alpha = [dimmer alpha] -0.0037;
dimmer.alpha -=alpha;
}
我会查看您当前在屏幕上的位置handlePanGesture:
查找您在视图中所处的百分比CGFloat percentage = nowPosition.y/self.view.frame.size.height;
然后将 alpha 设置为该值dimmer.alpha = 1.0 - percentage;
。这样,无论您移动到哪里,您都可以将 alpha 设置为距离底部有多近。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)