{"id":198890,"date":"2013-10-24T19:12:03","date_gmt":"2013-10-24T15:12:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=198890"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=198890","title":{"rendered":"<span class=\"post_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 UIDynamicAnimator \u0438\u0437 UIKit Dynamics \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 UICollectionView<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 SDK (\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a UIKit Dynamics) \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f UIView \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b UIDynamicItem. <\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. <\/p>\n<p>  \u0426\u0435\u043b\u044c\u044e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0442\u043e\u0439, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Messages \u043d\u0430 iOS 7:<br \/>  <a name=\"habracut\"><\/a><br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/6a6\/9f6\/262\/6a69f6262a634d391a0f3b6f72f2e032.jpg\" alt=\"image\"\/><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/UIKit\/Reference\/UIDynamicAnimator_Class\/Reference\/Reference.html\">UIDynamicAnimator<\/a> \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/uikit\/reference\/UICollectionView_class\/Reference\/Reference.html\">UICollectionView<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/uikit\/reference\/UICollectionViewLayout_class\/Reference\/Reference.html#\/\/apple_ref\/occ\/cl\/UICollectionViewLayout\">UICollectionViewFlowLayout<\/a>:<\/p>\n<pre><code class=\"objectivec\">#import &lt;UIKit\/UIKit.h&gt;  @interface DVCollectionViewFlowLayout : UICollectionViewFlowLayout  @end <\/code><\/pre>\n<p>  \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441 \u0442\u0438\u043f\u043e\u043c UIDynamicAnimator <\/p>\n<pre><code class=\"objectivec\"> #import &quot;DVCollectionViewFlowLayout.h&quot;  @interface DVCollectionViewFlowLayout()  \/\/\u043e\u0431\u044a\u0435\u043a\u0442-\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 @property (nonatomic, strong) UIDynamicAnimator *dynamicAnimator;  @end  @implementation DVCollectionViewFlowLayout  @synthesize dynamicAnimator = _dynamicAnimator;  -(id)initr{     self = [super init];     if (self){         _dynamicAnimator = [[UIDynamicAnimator alloc] initWithCollectionViewLayout:self];     }     return self; }  <\/code><\/pre>\n<p>  \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c UIDynamicAnimator. \u0410\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u043d\u0451\u043c \u043d\u0438\u0436\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"objectivec\"> #import &quot;DVCollectionViewFlowLayout.h&quot;   \/\/ .........  - (void)prepareLayout{          [super prepareLayout];          CGSize contentSize = [self collectionViewContentSize];     NSArray *items = [super layoutAttributesForElementsInRect:CGRectMake(0, 0, contentSize.width, contentSize.height)];          if (items.count != self.dynamicAnimator.behaviors.count) {         [self.dynamicAnimator removeAllBehaviors];                  for (UICollectionViewLayoutAttributes *item in items) {             UIAttachmentBehavior *springBehavior = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:item.center]; \/\/\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f (\u043d\u0430 \u0433\u043b\u0430\u0437)             springBehavior.length = 0.f;             springBehavior.damping = 1.f;             springBehavior.frequency = 6.8f;                          [self.dynamicAnimator addBehavior:springBehavior];         }     } }  - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{     return [self.dynamicAnimator itemsInRect:rect]; }  - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{     return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath]; }  - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{     CGFloat scrollDelta = newBounds.origin.y - self.collectionView.bounds.origin.y;     CGPoint touchLocation = [self.collectionView.panGestureRecognizer locationInView:self.collectionView];          for (UIAttachmentBehavior *springBehavior in self.dynamicAnimator.behaviors) {         CGPoint anchorPoint = springBehavior.anchorPoint;         CGFloat touchDistance = fabsf(touchLocation.y - anchorPoint.y);        \/\/\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f (\u043d\u0430 \u0433\u043b\u0430\u0437)  CGFloat resistanceFactor = 0.002;                  UICollectionViewLayoutAttributes *attributes = springBehavior.items.firstObject;                 CGPoint center = attributes.center;                  float resistedScroll = scrollDelta * touchDistance * resistanceFactor;         float simpleScroll = scrollDelta;                  float actualScroll = MIN(abs(simpleScroll), abs(resistedScroll));         if(simpleScroll &lt; 0){             actualScroll *= -1;         }                  center.y += actualScroll;         attributes.center = center;                  [self.dynamicAnimator updateItemUsingCurrentState:attributes];     }          return NO; }  -(void)dealloc{         [self.dynamicAnimator removeAllBehaviors];         self.dynamicAnimator = nil; }  <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442 UIAttachmentBehavior \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c item \u043a\u043b\u0430\u0441\u0441\u0430 UICollectionViewLayoutAttributes \u0438 \u0442\u043e\u0447\u043a\u043e\u0439 item.center (\u0446\u0435\u043d\u0442\u0440\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430). \u041a\u043e\u0433\u0434\u0430 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u043b\u0438 \u0442\u043e\u0447\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f, \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f. C \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432 damping \u0438 frequency \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441 \u0442\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  <a href=\"http:\/\/yadi.sk\/d\/VUpNmgR-BVyf9\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p>  \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0440\u043e \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0432 iOS 7:  <\/p>\n<ul>\n<li> <a href=\"http:\/\/www.teehanlax.com\/blog\/introduction-to-uikit-dynamics\/\">Introduction to UIKit Dynamics<\/a><\/li>\n<li> <a href=\"http:\/\/www.raywenderlich.com\/50197\/uikit-dynamics-tutorial\">UIKit Dynamics Tutorial<\/a><\/li>\n<li><a href=\"http:\/\/osxdev.ru\/blog\/ios\/137.html\">iOS 7 SDK: \u041e\u0431\u0437\u043e\u0440 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439<\/a><\/li>\n<li><a href=\"http:\/\/blog.denivip.ru\/index.php\/2013\/07\/%d1%8d%d1%84%d1%84%d0%b5%d0%ba%d1%82-%d0%bf%d0%b0%d1%80%d0%b0%d0%bb%d0%bb%d0%b0%d0%ba%d1%81%d0%b0-%d0%b2-ios-%d0%bf%d1%80%d0%b8%d0%bb%d0%be%d0%b6%d0%b5%d0%bd%d0%b8%d1%8f%d1%85\/\">\u042d\u0444\u0444\u0435\u043a\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0430\u043a\u0441\u0430 \u0432 iOS \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445<\/a><\/li>\n<li><a href=\"http:\/\/blog.denivip.ru\/index.php\/2013\/07\/%d0%be%d1%81%d0%b2%d0%b0%d0%b8%d0%b2%d0%b0%d0%b5%d0%bc-core-motion-%d0%b2-ios\/\">\u041e\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c Core Motion \u0432 iOS<\/a><\/li>\n<\/ul>\n<p>  <habracut\/> \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/198890\/\"> http:\/\/habrahabr.ru\/post\/198890\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 SDK (\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a UIKit Dynamics) \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f UIView \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b UIDynamicItem. <\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. <\/p>\n<p>  \u0426\u0435\u043b\u044c\u044e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0442\u043e\u0439, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Messages \u043d\u0430 iOS 7:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-198890","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198890"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198890\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}