Some ingenious tricks for iOS development 2

Some ingenious tricks for iOS development 2

Some ingenious tricks for iOS development 2

Is it possible to use only one pan gesture to replace all directions of UISwipegesture?

  1. - ( void )pan:(UIPanGestureRecognizer *)sender
  2. {
  3. typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {
  4. UIPanGestureRecognizerDirectionUndefined,
  5. UIPanGestureRecognizerDirectionUp,
  6. UIPanGestureRecognizerDirectionDown,
  7. UIPanGestureRecognizerDirectionLeft,
  8. UIPanGestureRecognizerDirectionRight
  9. };
  10. static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;
  11. switch (sender.state) {
  12. case UIGestureRecognizerStateBegan: {
  13. if (direction == UIPanGestureRecognizerDirectionUndefined) {
  14. CGPoint velocity = [sender velocityInView:recognizer.view];
  15. BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);
  16. if (isVerticalGesture) {
  17. if (velocity.y > 0 ) {
  18. direction = UIPanGestureRecognizerDirectionDown;
  19. } else {
  20. direction = UIPanGestureRecognizerDirectionUp;
  21. }
  22. }
  23. else {
  24. if (velocity.x > 0 ) {
  25. direction = UIPanGestureRecognizerDirectionRight;
  26. } else {
  27. direction = UIPanGestureRecognizerDirectionLeft;
  28. }
  29. }
  30. }
  31. break ;
  32. }
  33. case UIGestureRecognizerStateChanged: {
  34. switch (direction) {
  35. case UIPanGestureRecognizerDirectionUp: {
  36. [self handleUpwardsGesture:sender];
  37. break ;
  38. }
  39. case UIPanGestureRecognizerDirectionDown: {
  40. [self handleDownwardsGesture:sender];
  41. break ;
  42. }
  43. case UIPanGestureRecognizerDirectionLeft: {
  44. [self handleLeftGesture:sender];
  45. break ;
  46. }
  47. case UIPanGestureRecognizerDirectionRight: {
  48. [self handleRightGesture:sender];
  49. break ;
  50. }
  51. default : {
  52. break ;
  53. }
  54. }
  55. break ;
  56. }
  57. case UIGestureRecognizerStateEnded: {
  58. direction = UIPanGestureRecognizerDirectionUndefined;
  59. break ;
  60. }
  61. default :
  62. break ;
  63. }
  64. }

How can I keep the image from being deformed when stretching it?

  1. UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    (Someone just reminded me that this has been deprecated. The current method is called resizableImageWithCapInsets).

Why is it so slow when playing GIF? Is there a better library?

FlipBoard's is perfect for you. https://github.com/Flipboard/FLAnimatedImage

How to add pull-to-refresh in one sentence?

https://github.com/samvermette/SVPullToRefresh

  1. [tableView addPullToRefreshWithActionHandler:^{
  2. // prepend data to dataSource, insert cells at top of table view
  3. // call [tableView.pullToRefreshView stopAnimating] when done
  4. } position:SVPullToRefreshPositionBottom];

How to change the color of the small check mark in the cell of tableview to another color?

  1. _mTableView.tintColor = [UIColor redColor];

Originally my statusbar was lightcontent, but using UIImagePickerController caused the style of my statusbar to turn black. What should I do?

  1. - ( void )navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
  2. {
  3. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  4. }

How can I make my navigationbar transparent instead of blurry?

  1. [self.navigationBar setBackgroundImage:[UIImage new ]
  2. forBarMetrics:UIBarMetricsDefault];
  3. self.navigationBar.shadowImage = [UIImage new ];
  4. self.navigationBar.translucent = YES;

How to change the color and position of uitextfield placeholder?

Inherit uitextfield and override this method

  1. - ( void ) drawPlaceholderInRect:(CGRect)rect {
  2. [[UIColor blueColor] setFill];
  3. [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
  4. }

Why do you know so many weird tricks?

Go to stackoverflow and post questions, young man!

<<:  Is it Lanxiang again? A major bug appeared in WeChat's "group chat" function

>>:  How to quickly become familiar with a language

Recommend

Every drop of alcohol you drink is damaging your brain!

【Written at the end】 In 2018, a study in The Lanc...

Product Operation | How do stranger social products guide users?

Regarding stranger social products for the purpos...

Design of easily scalable game skill system from multiple perspectives

[[145670]] A well-expanded skill system can well ...

Why is the silver bracelet ineffective in testing poison?

Recently, a man in Yibin, Sichuan, picked mushroo...

The film law is here! Is the rating system far behind?

From its drafting in 2003 to its first review by ...

Snapdragon 820 vs. Tegra X1: Mobile? Console? The paths are different

The rise of mobile smart devices has gradually sh...

Game live streaming platform: Douyu, Huya competitive product analysis report

In this article, the author attempts to analyze t...