首页 > 代码库 > iOS开发的一些奇巧淫技2
iOS开发的一些奇巧淫技2
能不能只用一个pan手势来代替UISwipegesture的各个方向?
1 - (void)pan:(UIPanGestureRecognizer *)sender 2 { 3 4 typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) { 5 UIPanGestureRecognizerDirectionUndefined, 6 UIPanGestureRecognizerDirectionUp, 7 UIPanGestureRecognizerDirectionDown, 8 UIPanGestureRecognizerDirectionLeft, 9 UIPanGestureRecognizerDirectionRight10 };11 12 static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;13 14 switch (sender.state) {15 16 case UIGestureRecognizerStateBegan: {17 18 if (direction == UIPanGestureRecognizerDirectionUndefined) {19 20 CGPoint velocity = [sender velocityInView:recognizer.view];21 22 BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);23 24 if (isVerticalGesture) {25 if (velocity.y > 0) {26 direction = UIPanGestureRecognizerDirectionDown;27 } else {28 direction = UIPanGestureRecognizerDirectionUp;29 }30 }31 32 else {33 if (velocity.x > 0) {34 direction = UIPanGestureRecognizerDirectionRight;35 } else {36 direction = UIPanGestureRecognizerDirectionLeft;37 }38 }39 }40 41 break;42 }43 44 case UIGestureRecognizerStateChanged: {45 switch (direction) {46 case UIPanGestureRecognizerDirectionUp: {47 [self handleUpwardsGesture:sender];48 break;49 }50 case UIPanGestureRecognizerDirectionDown: {51 [self handleDownwardsGesture:sender];52 break;53 }54 case UIPanGestureRecognizerDirectionLeft: {55 [self handleLeftGesture:sender];56 break;57 }58 case UIPanGestureRecognizerDirectionRight: {59 [self handleRightGesture:sender];60 break;61 }62 default: {63 break;64 }65 }66 break;67 }68 69 case UIGestureRecognizerStateEnded: {70 direction = UIPanGestureRecognizerDirectionUndefined; 71 break;72 }73 74 default:75 break;76 }77 78 }
拉伸图片的时候怎么才能让图片不变形?
1 UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];2 (刚才有人提醒这个已经deprecated了哈,现在的方法叫resizableImageWithCapInsets).
怎么播放GIF的时候这么卡,有没有好点的库?
FlipBoard出品的太适合你了。https://github.com/Flipboard/FLAnimatedImage
怎么一句话添加上拉刷新?
https://github.com/samvermette/SVPullToRefresh
1 [tableView addPullToRefreshWithActionHandler:^{2 // prepend data to dataSource, insert cells at top of table view3 // call [tableView.pullToRefreshView stopAnimating] when done4 } position:SVPullToRefreshPositionBottom];
怎么把tableview里cell的小对勾的颜色改成别的颜色?
_mTableView.tintColor = [UIColor redColor];
本来我的statusbar是lightcontent的,结果用UIImagePickerController会导致我的statusbar的样式变成黑色,怎么办?
1 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; }
怎么把我的navigationbar弄成透明的而不是带模糊的效果?
1 [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationBar.shadowImage = [UIImage new]; self.navigationBar.translucent = YES;
怎么改变uitextfield placeholder的颜色和位置?
继承uitextfield,重写这个方法
1 - (void) drawPlaceholderInRect:(CGRect)rect { [[UIColor blueColor] setFill]; [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment]; }
你为什么知道这么多奇怪的花招?
去stackoverflow刷问题啊,少年!
iOS开发的一些奇巧淫技2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。