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

Xiaomi Mobile wants to make secondary SIM cards? Lei Jun is playing a big game

[[150227]] On the afternoon of September 22, Xiao...

"There was a cloud made of rain in the wind." What are clouds made of?

Produced by: Science Popularization China Author:...

Really understand AE expressions from scratch

Really understand AE expression resources from scr...

Do animals know their fate in advance?

© Brad Wilson Leviathan Press: At the beginning o...

CCTV investigates the truth about the 55-degree cup: Can you call this high-tech?

【Introduction】 Recently, a temperature-changing w...

Sad culture is popular, so is heartfelt marketing far behind?

Looking at the popular advertising cases today, i...