OC |
swift |
category |
extension:可以写在类外面 |
- (float) check: (int) count { } |
func check: (count: Int) -> Float { } |
int n = 0
n ++
|
var n: Int = 0
n += 1
|
NSString *str = @"你好"
str = [NSString stringwithformat:@"%s%d", str, n];
|
var str: String = "你好"
str += String(n)
|
NSArray * ary = [NSArray array]
ary = @[ [NSValue valueWithCGPoint:CGPointMake(0.9, 0.1)], [NSValue valueWithCGPoint:CGPointMake(9.8, 9.7)] ];
|
var ary = [NSValue]()
ary = [
NSValue(cgPoint: CGPoint(x: 0.1, y: 0.9)),
NSValue(cgPoint: CGPoint(x: 9.8, y: 9.7))
]
ary.append(NSValue(cgPoint: CGPoint(x: 0.1, y: 0.9)))
|
NSDictionary *dic |
var dic = [Int: CGPoint]()
字典可以用Int类型做key
dic[n] = CGPoint(x:x, y:y)添加值
没有NSMutableDictionary和NSDictionary 区分
|
UIColor *white = [UIColor whiteColor] |
let white:Color = UIColor.white |
UIView |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
self.view.addSubview(view)
|
UILabel |
var countLabel = UILabel(frame: CGRect(x:CellHeight, y:CGFloat(CellHeight*3+wh), width:CGFloat(ViewWidth-CellHeight*2), height:(CellHeight))) countLabel.textColor = UIColor.blue countLabel.layer.cornerRadius = 10 countLabel.layer.borderColor = UIColor.blue.cgColor countLabel.layer.borderWidth = 1 countLabel.textAlignment = NSTextAlignment.center countLabel.text = "您已走了0步" self.view.addSubview(countLabel) |
UIButton |
var diceV = UIButton(type: UIButtonType.custom)
diceV.frame = CGRect(x:CGFloat((ViewWidth-shaiziWH)/2), y:CGFloat(CellHeight*5+wh), width:shaiziWH, height:shaiziWH) diceV.setBackgroundImage(UIImage(named: "1"), for: UIControlState.normal) diceV.adjustsImageWhenDisabled = false diceV.addTarget(self, action: #selector(self.shakeDice), for: UIControlEvents.touchUpInside)
self.view.addSubview(diceV)
//添加的点击事件
@objc func shakeDice() { }
|
[NSTimer scheduledTimerWithTimeInterval:0.2 repeats:YES block:^(NSTimer * _Nonnull timer) { // }]; |
Timer.scheduledTimer(withTimeInterval: TimeInterval(0.2), repeats: false, block: { // }) |
CAKeyframeAnimation *runAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; runAnimation.values = [NSArray arrayWithArray:ary]; runAnimation.fillMode = kCAFillModeForwards; runAnimation.removedOnCompletion = NO;// 是否在动画完成后从 Layer 层上移除 回到最开始状态 runAnimation.duration = 1.0f; runAnimation.repeatCount = 0; peopleV.layer.anchorPoint = CGPointMake(0, 0); [peopleV.layer addAnimation:runAnimation forKey:nil]; |
let runAnimation:CAKeyframeAnimation = CAKeyframeAnimation(keyPath: "position")//只能写position runAnimation.values = [NSValue(cgPoint: geziDic[start]!), NSValue(cgPoint: geziDic[end]!)] runAnimation.duration = 1.0 runAnimation.repeatCount = 0 runAnimation.isRemovedOnCompletion = false runAnimation.fillMode = kCAFillModeForwards peopleV.layer.anchorPoint = CGPoint(x: 0, y: 0)//默认是(0.5, 0.5)
peopleV.layer.add(runAnimation, forKey: nil)
|
请发表评论