//
Viewcontroller.m
The Dancing UIView
//
Created by Big Huan on 16/1/18.
COPYRIGHT©2016 year BJSXT. All rights reserved.
//
/********************************************************/
#import "ViewController.h"
#define Screen_width [UIScreen mainscreen].bounds.size.width
#define Screen_height [UIScreen mainscreen].bounds.size.height
A lowercase k-defined identifier acts only on a single compilation unit
All letters large writing for the global
@interface Viewcontroller ()
@property (nonatomic, Strong) UIView * Flyview;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
[Self.view AddSubview:self.flyView];
Nstimer * timer = [Nstimer timerwithtimeinterval:0.01 target:self selector: @selector (flyaction) Userinfo:nil repeats: YES];
[[Nsrunloop Mainrunloop] Addtimer:timer Formode:nsdefaultrunloopmode];
[Nstimer scheduledtimerwithtimeinterval:0.01 target:self selector: @selector (flyaction) Userinfo:nil Repeats:yes];
}
-(void) Flyaction {
CGRect rect = self.flyView.frame;
static int X = 1;
static int Y = 1;
if (rect.origin.x < 0 | | rect.origin.x + rect.size.width > Screen_width) {
X *=-1;
}
if (Rect.origin.y < | | RECT.ORIGIN.Y + rect.size.height > Screen_height) {
Y *=-1;
}
Rect.origin.x + = x;
RECT.ORIGIN.Y + = y;
Self.flyView.frame = rect;
}
-(UIView *) Flyview {
if (!_flyview) {
_flyview = [[UIView alloc] Initwithframe:cgrectmake (0, 20, 50, 50)];
_flyview.backgroundcolor = [Uicolor Orangecolor];
}
return _flyview;
}
@end
/**************************************************************/
iOS common technology-dancing blocks