The original link

Update: A couple of weeks ago we posted a short episode titled “Xcode 10.1 did not fix a crash caused by Assets on iOS 9”. According to the latest news, Apple has fixed the issue on the server side, and developers have uploaded the IPA package from Xcode 10.1 to the Apple background. Apple will fix it automatically as it processes the package. Crash will not happen on iOS 9

The following article was published on wechat last week:

  • Possible problems with YYAsyncLayer
  • Notes for isEqual and Hash in iOS
  • Research on RSA Principle
  • What is Code Quality? Write code with your head

The main contents of this knowledge collection include:

  • Study the relationship between wKWebView’s subviews and
  • How do I make UIImagePickerController landscape
  • Sentences break up
  • Scattered points in the Safe Area

Study the relationship between WKWebview’s subviews and

Authors: Hite and Luyan

The problem comes from the requirement that when webView bounce is pulled down, the custom view is displayed in the leaked section. Similar to the “this page is provided by ****” interaction when opening a public account on wechat.

After some testing, there are three key points to achieve this functionality;

  1. Set up thewebview.scrollView.backgroundColor = [UIColor clearColor];The purpose is to leak out our custom view when we pull down the entire page. (It should be noted here that the drop-down page appearsbounceWhen it works, what leaks out iswkscrollview; Why is that, I guess, because Safari renders the bounce effect inwkscrollviewRefer to thisThe test page, open it in Safari)
  2. I’m going to combine that with 1, and I’m going to put this custom view inWKWebviewWKScrollViewBetween (guess,webview.scrollViewWKScrollViewProxy object, andWKScrollViewIs the proxy element, whether really need to see the source code).
  3. Add a custom view toWKScrollViewThe timing is- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollViewRather than- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigationSome styles take effect at different times depending on how the page is written, and loading the page is not a good time.

At the time of generating webview, set the webview. ScrollView. BackgroundColor = [UIColor clearColor]; . < span style=”background-color:red”> Or write a style; Or you can use to set the color of the body, depending on the situation;

  1. When the body color is set to#ffffffWhite, whenever YOU set the body color it’s not overwritten, rightwebview.scrollView.backgroundColorThe color.
  2. When the color is set toThe white, will overwritewebview.scrollView.backgroundColor

By comparing the HTML DOM hierarchy with the WKWebview hierarchy,

The following findings were found;

  1. When you pull down in HTML, the background element behind the bounce effect isWKScrollView, so setting the body color will set toWKScrollViewBackground color.
  2. All other elements in HTML are made up ofWKContentViewNesting. When the entire page is long and needs to be paginated, it is divided into multiple pagesWKCompositingViewDisplay one by one;

There is a problem with using the above scheme to display custom elements when pulling down;

  1. At the beginning of the slidescrollViewWhen, setwebview.scrollView.backgroundColor, will cover the background color set by H5 itself, so H5 should try not to rely on the background color of body to do sliding background;
  2. Some pages, such asTest page 2There’s a headfixedElement, and the bounce background color will also leak out when pulled down. At this point, if the background color is set to transparent, there is a strange leak, this should not leak. If you want to solve this problem, if you really want to solve this problem, you might have to read the HTML style, which is a little bit more troublesome.
  3. A neat solution to problem 2 is to put the missing custom elements infixedElement, such as wechat. The specific style can beTest page 2Put it in wechat to see the effect.

If we really want to solve problem 2, we still need to find a solution. I hope we can find a solution after seeing the source code of Webkit2.

How do I make UIImagePickerController landscape

Author: halohily

A lot of you, when you’re developing landscape apps, and you use your system’s UIImagePickerController, you’ll find that it only supports portrait by default. The author also encountered this problem, after some exploration, the following way is the best effect:

First of all, before the PRESENT UIImagePickerController object picker here, Set picker modalPresentationStyle to UIModalPresentationOverCurrentContext when run will find landscape popup, it can also be normal just rotating equipment when it does not follow normal rotation direction.

Next, add a category for UIImagePickerController, override shouldAutorotate to return true, Rewrite supportedInterfaceOrientations method returns UIInterfaceOrientationMaskAll. When you run it again, you will find that not only can you pop landscape, but you can also rotate normally.

Sentences break up

Author: Lefe_x

Break the following paragraph into sentences. What plan would you use?

The knowledge set is made up of several like-minded partners. Do you know anything about the team? We have been together for more than a year! I want to say: "We are the best!"Copy the code

The solutions I have in mind are: regular expressions; Use NSScanner; Using componentsSeparatedByCharactersInSet:; But these schemes are more troublesome, and then I stumbled upon the following method.

The code is as follows:

NSString *text = @" Knowledge clique is made up of several like-minded partners. Do you know anything about the team? We have been together for more than a year! I want to say: "We are the best!" ";
[text enumerateSubstringsInRange:NSMakeRange(0, [text length]) options:NSStringEnumerationBySentences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
    NSLog(@"sentence: %@ range: %@", substring, NSStringFromRange(substringRange));
}];
Copy the code

The running results are as follows:

Sentence: The knowledge set is made up of several like-minded partners. range: {0.18} Sentence: Do you know anything about the team? range: {18.9} We spent time together1More than years! range: {27.17} Sentence: I want to say: "We are the best!" range: {44.13}
Copy the code

Scattered points in the Safe Area

Author: There is no filling weibo.com/u/660346950…

Take a look at figure 1.

As we all know, iOS 11 introduced the concept of Safe Area. Adding a subview to a XIB or storyboard will be added to the Safe Area. For example, when you add a view on VC, the constraints on top, bottom, left and right are 0 respectively, which is displayed differently on iPhone X and iPhone 6, as shown below. This problem does not occur with pure code creation because subviews are added directly to self.view.

Apparently, there will be a 34pt height white space underneath the iPhone X. Print self.view.Safeareainsets of the two models, as shown below.

So for now, I’d like to see no white space at the bottom on the iPhone X. The page looks just like the iPhone 6. However, safeAreaInsets are read-only properties and cannot be modified.

For the first method, Align Bottom to: Safe Area = -34. However, if a new model is released later, this value is no longer suitable because it is not recommended.

The second method, on the BOTTOM constraint, directly references superView, as shown below.

A few additional points:

  • - additionalSafeAreaInsets:controllerWe can extend the security zone if we setself.additionalSafeAreaInsets = UIEdgeInsetsMake(20, 0, 0, 20);Add the corresponding margin value to the original safeAreaInsets value. If the original was {10, 0, 0, 10}, the resulting margin is {30, 0, 0, 30}.
  • - (void)viewSafeAreaInsetsDidChange:This method is triggered when the view’s security zone changes, and you can use this method to handle the UI layout when the security zone changes.
  • - insetsLayoutMarginsFromSafeArea:The default value is YES, if set to NO, all view layouts will be ignoredsafeAreaInsetsThis property right here. This only works for pure code layout views, if yesxiborstoryboardLayout words don’t work. Commonly used intableViewIn the majority.

Pay attention to our

Please follow our official account ios-tips and join our group to discuss issues. You can leave messages on the public account ios, flutter and other keywords to get into the group.