In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use iOS to achieve the effect of suspension window. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Demand
Add a floating window to the top of an app application, just like the ios system AssistiveTouch can slide left and right, but will eventually stop on the left or right.
Realization idea
Add a UIWindow to the top level of the application view, use this UIWindow as a floating window, add mobile gesture monitoring to the UIWindow, let the floating window move with the finger, and let it move to the side in an animated way when it is released.
Code / / suspension window test / / create a suspension window mwindow = [AssistiveTouch alloc] initWithFrame:CGRectMake (100,200,40,40) imageName:@ "1.png"]; / / ios9 window to set rootview or crash UIViewController * controller = [[UIViewController alloc] init]; mwindow.rootViewController = controller;// shows the suspension window. [self.window makeKeyAndVisible]; / / add moving gestures UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector (locationChange:)]; pan.delaysTouchesBegan = YES; [self addGestureRecognizer:pan]; / / change position-(void) locationChange: (UIPanGestureRecognizer*) p {/ / [[UIApplication sharedApplication] keyWindow] CGPoint panPoint = [p locationInView: [[UIApplication sharedApplication] keyWindow]] If (p.state = = UIGestureRecognizerStateBegan) {[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector (changeColor) object:nil]; _ imageView.alpha = 0.8;} else if (p.state = = UIGestureRecognizerStateEnded) {[self performSelector:@selector (changeColor) withObject:nil afterDelay:4.0];} if (p.state = = UIGestureRecognizerStateChanged) {self.center = CGPointMake (panPoint.x, panPoint.y) } else if (p.state = = UIGestureRecognizerStateEnded) {if (panPoint.x = kScreenHeight-HEIGHT/2-40 & & panPoint.x > = 20+WIDTH/2) {[UIView animateWithDuration:0.2 animations: ^ {self.center = CGPointMake (panPoint.x, kScreenHeight-HEIGHT/2);}];} else if (panPoint.x
< WIDTH/2+15 && panPoint.y >KScreenHeight-HEIGHT/2) {[UIView animateWithDuration:0.2 animations: ^ {self.center = CGPointMake (WIDTH/2, kScreenHeight-HEIGHT/2);}];} else {CGFloat pointy = panPoint.y
< HEIGHT/2 ? HEIGHT/2 :panPoint.y; [UIView animateWithDuration:0.2 animations:^{ self.center = CGPointMake(WIDTH/2, pointy); }]; } } else if(panPoint.x >KScreenWidth/2) {if (panPoint.y = kScreenHeight-40-HEIGHT/2 & & panPoint.x
< kScreenWidth-WIDTH/2-20) { [UIView animateWithDuration:0.2 animations:^{ self.center = CGPointMake(panPoint.x, 480-HEIGHT/2); }]; } else if (panPoint.x >KScreenWidth-WIDTH/2-15 & & panPoint.y
< HEIGHT/2) { [UIView animateWithDuration:0.2 animations:^{ self.center = CGPointMake(kScreenWidth-WIDTH/2, HEIGHT/2); }]; } else { CGFloat pointy = panPoint.y >KScreenHeight-HEIGHT/2? KScreenHeight-HEIGHT/2: panPoint.y; [UIView animateWithDuration:0.2 animations: ^ {self.center = CGPointMake (320-WIDTH/2, pointy);}] This is the end of the article on "how to achieve the suspended window effect of iOS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.