我一直在复制2013 WWDC Session 217"探索iOS 7上的滚动视图".我正在使用Xcode 7 beta 2,我的项目仅限iOS 9.
我试图以类似于会话217中提供的方式UIDynamicAnimator使用my UICollectionViewLayout来模仿Messages.app的感觉.我UICollectionViewLayout是一个习惯性的,出于某种原因,我的细胞似乎在我的项目中以圆周运动反弹.
这是我的自定义布局代码.
// Didn't write this code myself, but should be pretty simple to follow. @Goles
#import "VVSpringCollectionViewFlowLayout.h"
@interface VVSpringCollectionViewFlowLayout()
@property (nonatomic, strong) UIDynamicAnimator *animator;
@end
@implementation VVSpringCollectionViewFlowLayout
-(id)init {
if (self = [super init]) {
_springDamping = 0.5;
_springFrequency = 0.8;
_resistanceFactor = 500;
}
return self;
}
- (id)initWithCoder:(nonnull NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
_springDamping = 0.5;
_springFrequency …Run Code Online (Sandbox Code Playgroud) ios uicollectionview uicollectionviewlayout uidynamicanimator swift
我有一个ViewController已经在InterfaceBuilder中配置为使用AutoLayout的所有子视图.布局工作正常.
我想使用UIDynamicAnimator提供的酷重力效果使其中一个子视图反弹.我认为这不适用于AutoLayout,但我尝试了它确实如此.它运作得很好!
我的问题是,这是预期的行为吗?是否会在某处造成问题?Apple是否提供有关组合AutoLayout和UIDynamicAnimators的任何指导?
这是代码,对任何感兴趣的人:
var boundaryFrame = self.buttonBackgroundView.frame
boundaryFrame = CGRect(x: 0,
y: boundaryFrame.origin.y + (boundaryFrame.height + 1),
width: self.view.frame.width,
height: 2)
self.animator = UIDynamicAnimator(referenceView: self.view)
var gravity = UIGravityBehavior(items: [self.buttonBackgroundView])
gravity.magnitude = 0.5
var collision = UICollisionBehavior(items: [self.buttonBackgroundView])
var boundaryId: NSMutableString = NSMutableString(string: "bottomBoundary")
let boundaryPath = UIBezierPath(rect: boundaryFrame)
collision.addBoundaryWithIdentifier(boundaryId, forPath: boundaryPath)
let bounceProperties = UIDynamicItemBehavior(items: [self.buttonBackgroundView])
bounceProperties.elasticity = 0.5
// Move it up before causing it to bounce down to its original location
self.setMeUpTopConstraint.constant = 10
self.view.setNeedsUpdateConstraints() …Run Code Online (Sandbox Code Playgroud) 我在导航控制器中有一个视图.
然后我在这个视图中添加一个子视图并偏移其原点高度,使其仅覆盖屏幕的一半(另一半从屏幕底部溢出).我希望能够向上拖动此视图,但是当它到达导航栏的底部时会停止.
我正在使用a UIPanGestureRecognizer来处理视图的拖动,这很好但是它似乎不会停在边界.
这是我正在使用的代码:
bottomNavbarY = UIApplication.sharedApplication().statusBarFrame.size.height + self.navigationController!.navigationBar.frame.size.height
view.addSubview(pullover.view)
pullover.view.frame.origin.y = pulloverOffset
var animator = UIDynamicAnimator(referenceView: view)
var collision = UICollisionBehavior(items: [pullover.view])
collision.translatesReferenceBoundsIntoBoundary = true
collision.addBoundaryWithIdentifier("upper", fromPoint: CGPointMake(0, bottomNavbarY), toPoint: CGPointMake(UIScreen.mainScreen().bounds.size.width, bottomNavbarY))
animator.addBehavior(collision)
Run Code Online (Sandbox Code Playgroud)
然而,当我向上拖动覆盖视图时,它从不与任何边界相互作用,它只是直接通过.我究竟做错了什么?是否可以使用边界来停止用户以这种方式拖动的视图?
我已经阅读了文档,我很尴尬地说我很困惑.
场景:
我有一个UIView,就像一个容器3 UIButtons.这个容器最初是边界的{0, 0, 35, 35},每个按钮里面都有相同的坐标(带alpha0).在用户的特定动作上,容器改变边界{0, 0, 100, 35},并且按钮分别用alpha1 动画到x-origin 5,35和65,使得它们在调整大小的容器内展开.我将此称为容器的展开状态.用户执行相同操作,将其切换回原始合同状态.
目标:
我目前正在使用[UIView animateWithDuration:]块进行此操作,但是想使用它UIDynamicAnimator来添加弹性效果,这样,当切换到展开状态时,容器会通过反弹调整大小(稍微调整大小,然后弹回到目标边界),按钮也会弹跳(向前移动一点,然后弹回到目标边界).
困惑:
UIDynamicAnimator,UIDynamicBehavior,UIAttachmentBehavior,UIDynamicItem.....所有这些都导致我的理解UIKitDynamic溢出.我想我应该使用UISnapBehavior,但我不知道如何去做.
我正在查看UIPushBehavior的Apple文档,它让我在瞬时模式下感到困惑.我知道加速公式是Force = Mass*acceleration.我假设视图的质量是宽度*高度*密度(1).文档描述了推送幅度如下:
默认幅度为零,相当于无力.应用于密度值为1.0的100点×100点视图的大小为1.0的连续力矢量导致在角度或pushDirection属性指示的方向上的视点加速度为100点/秒2.
这在连续推动方面是有意义的,它提供恒定的加速度.它没有说任何关于皮肤推进的内容.如何理解1级瞬时推动对100x100视图的速度?
physics ios7 uidynamicbehavior uidynamicanimator uipushbehavior