Notes on Sina Weibo analysis of IOS advanced interview (I): interview questions related to UI view


Thanks for watching, please pay more attention!For more interview articles and answers, please watch the interview collection!

Uitableview related

1、 Reuse mechanism
1. How does IOS implement the cell reuse mechanism?
  • A1-A7Use the sameidentifer, whentableViewSlide up,A1After the page is marked out, it is put into the reuse pool.
  • WhenA7When you are about to show it, you will first view it in the reuse poolidentiferofcellIt can be reused. If there is one, it will be directly taken out for use. If there is none, a new one will be createdcell

Interview notes

Xiaobian has prepared some advanced interview materials here,The latest interview big factory often asks an interview answer。 I hope I can really help you improve your technology!

2. How to implement reuse mechanism manually?

  • ViewReusePoolClass declaration
  • ViewReusePoolClass implementation
  • dequeueReusableViewFunction implementation
  • addUsingView:Function implementation
  • resetFunction implementation
  • ViewReusePoolUse of classes

2、 Data source synchronization problem

  • When the data source isMain threadThere aredeleteOperation, at the same timeChild threadThere’s another one on theLoad moreWhen the data is manipulated, theData source synchronization problem

1. Data source synchronization solution

a. Concurrent access, data copy
  • Child threadreturnMain threadThe deleted data is still included in the data.

  • stayMain threadWhen deleting, record the operation. Later inChild threadWhen data is synchronized, the deletion operation is synchronized.

b. Serial access
  • takeChild threadData synchronization andMain threadAll delete operations are put into oneSerial queueExecute in.
  • The deletion action may be delayed.

Event delivery & view response

1、 Uiview and calayer

1. What is the relationship and difference between uiview and calayer?

a. Relationship
  • UIViewObjectlayerPoint to aCALayervariable
  • UIViewObjectbackgroundColorProperty, yesCALayerEncapsulation of an attribute with the same name.
  • UIViewThe display part is composed ofCALayerMediumcontentsTo decide.contentsCorrespondingbacking storeIt’s actually abitmapBitmap for.
b. Distinction
  • UIViewProvide them with content, handle touch and other events, and participate in the response chain.
  • CALayerResponsible for displaying contentcontents

2. Why is uiview responsible for touching events and calayer responsible for displaying them?

  • Design patterns,Single responsibilityprinciple.

2、 Event delivery and view response chain

1. When you click View C2, how does the system find the response view?

a. Process of event delivery
  • When the user clicks the screen, the event is displayedUIApplicationAccept and pass on toUIWindow
  • UIWindowcallhitTestFunction, inhitTestInternal callpointInsideDetermine whether the event is in the view.
  • if it isfalse, return to the view and the event delivery process ends.
  • if it istrue, thenFlashback traversalOf this viewSubview, and callSubviewofhitTestFunction.
  • Find the endhitTestbytrueofSubview, and return in turn, and the event transfer process ends.
b、hitTestSystem internal implementation
  • Called in the current view subviewhitTestFunction, you need to convert the current coordinates toSubviewCoordinates in.

2. How to make only the circular area of the square picture accept the event response?

  • Override viewpointInsideFunction to make the click area return within a circular rangetrue, otherwise returnfalse
Thank you for watching! The article series continues to update and like to see again. Thank you for watching. Please pay more attention!