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

Tips on how to get an operational plan with millions of PVs!

There are two types of information platforms on t...

How to prevent car fires in the hot summer?

Summer is the peak season for spontaneous combust...

He Wei Element Flow Yoga System Basic Teacher Training

Introduction to the basic teacher training resour...

Will iOS 9 become more stable?

iOS has undergone tremendous changes since iOS 7,...

Deconstructing the universal formula for e-commerce operations!

E-commerce operation is the most special operatio...

How to create opium-like articles that users can’t stop reading? (Down)

Fear, excitement, novelty and confusion - what ki...

4 bad habits in the kitchen may cause family members to suffer from cancer!

Planning丨Yinuo Editor: Yinuo Visual丨Zhang Shan Re...

Home Guidelines for People Infected with COVID-19 (First Edition)

Source: National Health Commission official websi...