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

Community Operation: How do I operate the community?

The essence of a community is connection. It is a...

2-year-old boy found 6 live worms in his eyes! Change these habits now...

Expert in this article: Li Mingwu, Chief Physicia...

618. How to monitor the Double Eleven promotional activities?

Every year’s 618 is very special. At that time, a...

How to place a high-quality advertisement? Advertising tips!

What is a good advertisement? Everyone has a diff...

December 2021 "Science" Rumor List: Does nuclear heating have radiation?

Does nuclear heating have radiation? The more nat...

“Riding on the popularity” doesn’t work anymore? No, it was ruined!

At the beginning of the article, we are going to ...

There are so many online promotion channels, which one is suitable for us?

I still remember when I first entered the industr...

How to operate Pinduoduo paid membership!

There are endless ways to play with paid membersh...

My hairline is gradually moving back. Am I facing a "hair loss crisis"?

Hair loss has always been a headache for young an...

What superpowers do growth hackers need?

I've recently been reading Fan Bing's &qu...