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

Hundreds of iOS apps exposed to FREAK vulnerability risk

Citing a report from foreign media Ars Technica, ...

iOS 9 Learning Series: How UIStackView Makes Your Development Easier

Previously we covered the new features of Swift 2...

The master teaches you how to play with Excel and gain efficient life lessons

Different from the boring traditional teaching me...

The Marketing Dilemma of 618

There is a promotional festival called 618 every ...

2 tips to double your conversion rate! Which one have you used?

In previous articles, Qingguajun has always empha...

Microsoft will stop unlocking WP7.x devices after December 31

According to foreign media reports, Microsoft rece...

This magical material can make planes land more safely!

An airplane is a very complex means of transporta...

Hillhouse Capital “failed”, Zhang Lei “lost his voice”

The high-profile Hillhouse seems to have lost its...

To programmers: 8 reasons why users hate your mobile app

There are tens of thousands of mobile apps on the...

Internet enterprise operation and promotion plan (mind map)

We should all know that there are several work sc...

Strategies for creating highly active live streaming rooms!

In the past two years, live streaming has been ve...