iOS common technology-dancing blocks

Source: Internet
Author: User

//
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.