printint(3.14159)#3printtype(3),type(3.14159)#int floatprintfloat(3)#3.0
#floating point number have around 15 decimal digits of accuracyprint3.1415926535897932384626433832795028841971#3.14159265359#If one operand is a decimal (float), the answer is decimalprint1.0/3,5.0/2.0#0.333333333333 2.5
Variables
命名方式為字母或是“_” Dynamic
#The ones digit of a numbernum=49tens=num//10ones=num%10printtens,onesprint10*tens+ones,num
Python modules - extra functions implemented outside basic Python.
importmath#access to standard math functions, e.g; trigprintmath.pi#3.14159265359
Conditions
#Return True if year is a leap year, false otherwisedefis_leap_year(year):if(year% 400) ==0:returnTrueelif(year% 100) ==0:returnFalseelif(year% 4) ==0:returnTrueelse:returnFalseyear=2012leap_year=is_leap_year(year)ifleap_year:
printyear,"is a leap year"else:printyear,"is not a leap year"
+(void)animateWithDuration:(NSTimeInterval)duration#how long you want it to take for thing to appear on screen.(It does what's in block immediately)But the appearance of it is going to happen over time.
delay:(NSTimeInterval)delay#how long to wait to start doing it.options:(UIViewAnimationOptions)optionsanimations:(void(^)(void))animations#in this block is where you change "frame, transform and alpha".completion:(void(^)(BOOLfinished))completion;#do another animation,when the animation completes.
Set up physics relating animatable objects and let them run until they resolve to stasis.Easily possible to set it up so that stasis never occurs, but that could be performance problem.
只要物件繼承UIView類別,就自動擁有動態行為的能力.
STEPS
1. Create a UIDynamicAnimator
UIDynamicAnimator*animator=[[UIDynamicAnimatoralloc]initWithReferenceView:aView];#If animating views, all views must be in a view hierarchy with reference view at the top.
2. Add UIDynamicBehaviors to it (gravity, collisions, etc.)
#Create and add UIDynamicBehaviors.UIGravityBehavior*gravity=[[UIGravityBehavioralloc]init];[animatoraddBehavior:gravity];
3. Add UIDynamicItems (usually UIViews) to the UIDynamicBehaviors.
#The items have to implement the UIDynamicItem protocol ... @protocolUIDynamicItem@property(readonly)CGRectbounds;#drawing area of the item.@property(readwrite)CGPointcenter;#the position of the item.@property(readwrite)CGAffineTransformtransform;@end
-(void)updateItemUsingCurrentState:(id<UIDynamicItem>)item;#If you change center or transform while animator is running, you must call UIDynamicAnimator’s
@propertyUIPushBehaviorModemode;# Continuous or Instantaneous@propertyCGVectorpushDirection;@propertyCGFloatmagnitude/angle;# magnitude 1.0 moves a 100x100 view at 100 pts/s/s
the behavior will be sent this message when its animator changes.