[英]changing the Opacity of UIView by swipe
我看过其他一些可以改变iPhone屏幕亮度的应用程序。 我认为他们只是放置一个UIView并将其backgroundColor设置为黑色,然后每当用户在屏幕上滑动时,不透明度就会随着手指的滑动而变化。
任何人都可以帮助我,我怎么能模仿这个功能。
您可以仅在顶部添加UIView的叠加层(黑色)。
(如果视图中没有用户相关的控件(例如按钮,步进器等),那么就可以。例如,您在UIView上只有一个UITextView,则可以在UITextView的顶部添加黑色的UIView。
(在顶部)黑色UIView - > UITextView - > UIView
然后,您可以使用来控制黑色UIView的alpha分量
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *touchesArray = [touches allObjects];
for(int i=0; i<[touchesArray count]; i++) {
UITouch *touch = (UITouch *)[touchesArray objectAtIndex:i];
CGPoint point = [touch locationInView:nil];
//set the relationship between point and alpha. Maybe when x increases then alpha increases. You do the math.
}
}
顺便说一下,将黑色UIView的alpha设置为0.0到0.7(请记住,将其设置为全1.0会将屏幕设置为全黑。)
设置alpha:
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationDuration:duration];
[blackView setAlpha:alphaCounter];
} [UIView commitAnimations];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.