First, the simple use of uialertcontroller in iOS9
It is clear that the simple Uialertview has not been used, and I feel very sad.
Create
Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Started" message:@ "Started!" PreferredStyle: Uialertcontrollerstyleactionsheet];
Uialertcontrollerstyleactionsheet is displayed at the bottom of the screen
Uialertcontrollerstylealert is displayed in the middle
Set button
Uialertaction *cancel = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil];
Uialertaction *defult = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault Handler:nil];
Uialertaction *destructive = [uialertaction actionwithtitle:@ "destructive" style:uialertactionstyledestructive H Andler:nil];
Add button
[Alert Addaction:cancel];
[Alert Addaction:defult];
[Alert addaction:destructive];
Show
[Self Presentviewcontroller:alert animated:yes completion:nil];
——----——————//complex, add TextField, and listen.
Note: text input box can only be added to alert style, Actionsheet is not allowed
[Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {
Textfield.placeholder = @ "Landing";
}];
[Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {
Textfield.placeholder = @ "password";
Textfield.securetextentry = YES;
}];
[Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {
Textfield.placeholder = @ "Add listening code";
To set up a proxy for Uitextfieldtext
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (alerttextfieldtextdidchange:) Name: Uitextfieldtextdidchangenotification Object:textfield];
}];
[Self Presentviewcontroller:alert animated:yes completion:nil];
Monitoring method implementation
-(void) Alerttextfieldtextdidchange: (nsnotification *) notification
{
Uialertcontroller *alert = (Uialertcontroller *) Self.presentedviewcontroller;
if (alert) {
Subscript 2 is the last one, adding a listening alert.textfields[2]
Uitextfield *lisen = alert.textfields[2];
Limit output length, more than 6 not allow Click to confirm key
More than 6 buttons turn gray enabled = NO;
Uialertaction *action = Alert.actions.lastObject;
action.enabled = Lisen.text.length <= 6;
}
}
The effect is like this!
Second, Nstimer
is Nstimer accurate? What if you're not ready?
Inaccurate. It is usually used for the processing of periodic time with a certain time span!
Processing timer can be multi-threaded, in the game with Cadisplaylink.
/**
Parameter description
1. Time interval, double
2. Listening for clock-triggered objects
3. Calling methods
4. UserInfo, can be any object, usually pass nil
5. Repeats: whether to repeat
*/
The Scheduledtimerwithtimeinterval method essentially creates a clock,
The mode to be added to the run loop is Defaultrunloopmode
// ----------------------------------------------
1>
Self.timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (updatetimer:) userinfo:@ " Hello timer "Repeats:yes";
// ----------------------------------------------
2> and 1 equivalence
Self.timer = [Nstimer timerwithtimeinterval:1.0 target:self selector: @selector (updatetimer:) Userinfo:nil Repeats:Y ES];
Add a timer to the run loop
Mode: Default run-cycle mode
[[Nsrunloop Currentrunloop] AddTimer:self.timer Formode:nsdefaultrunloopmode];
// ----------------------------------------------
3>
Self.timer = [Nstimer timerwithtimeinterval:1.0 target:self selector: @selector (updatetimer:) Userinfo:nil Repeats:YES ];
Add a timer to the run loop
Mode: Nsrunloopcommonmodes running cycle mode (monitor scrolling mode)
[[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];
Stop clock, invalidate is the only way to stop the clock
Once the Invalidate method is called, the timer is invalid, and if you start the clock again, you need to re-instantiate
[Self.timer invalidate];
Third, ScrollView
/**
Zoom in and Zoom out
1> Setting up Agents
2> specifying the maximum/minimum zoom ratio
*/
The setter of the image
-(void) SetImage: (UIImage *) image
{
_image = image;
Set the contents of an image view
Self.imageView.image = image;
Make image view automatically resize based on image
[Self.imageview SizeToFit];
Tell ScrollView the actual size of internal content
Self.scrollView.contentSize = image.size;
}
/**
In the Getter method
* If the property itself, use the _ member variable
* If it is a different attribute, use self. Getter method, which guarantees that if the object is not instantiated, it can be created and loaded in a timely manner.
*/
-(Uiimageview *) ImageView
{
if (_imageview = = nil) {
_imageview = [[Uiimageview alloc] init];
[Self.scrollview Addsubview:_imageview];
}
return _imageview;
}
-(Uiscrollview *) ScrollView
{
if (_scrollview = = nil) {
_scrollview = [[Uiscrollview alloc] initWithFrame:self.view.bounds];
Setting properties
Set margins
_scrollview.contentinset = Uiedgeinsetsmake (20, 20, 20, 20);
Do not display horizontal scroll marks
_scrollview.showshorizontalscrollindicator = NO;
Do not display vertical scroll marks
_scrollview.showsverticalscrollindicator = NO;
Offset position
_scrollview.contentoffset = cgpointmake (0, 0);
Cancels the spring effect, the content is fixed, do not want to appear the spring effect when
Don't confuse the bounds attribute.
_scrollview.bounces = NO;
Set up Proxy
_scrollview.delegate = self;
Set maximum/Minimum zoom ratio
_scrollview.maximumzoomscale = 2.0;
_scrollview.minimumzoomscale = 0.2;
[Self.view Addsubview:_scrollview];
}
return _scrollview;
}
-(void) viewdidload
{
[Super Viewdidload];
Set image
Self.image = [UIImage imagenamed:@ "Minion"];
UIButton *btn = [UIButton buttonwithtype:uibuttontypecontactadd];
Btn.center = Self.view.center;
[Self.view ADDSUBVIEW:BTN];
[Btn addtarget:self Action: @selector (click) forcontrolevents:uicontroleventtouchupinside];
}
-(void) Click
{
Move the offset position of a large image
Cgpoint offset = Self.scrollView.contentOffset;
Offset.x + = 20;
Offset.y + = 20;
Note: Setting Contentoffset ignores contentsize
Self.scrollView.contentOffset = offset;
}
Proxy methods for #pragma mark-uiscrollview
/**
1> set up the proxy
2> specifies the maximum and minimum zoom ratio
Indicates that the ScrollView can be scaled
The "return value" of the proxy method is actually the controller telling the scrolling view that the Uiimageview is to be scaled.
*/
Tell ScrollView who the view to zoom to, the specific scaling implementation, is done by ScrollView
1> ScrollView to know who to scale
-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView
{
return self.imageview;
}
2> scrolling view is about to start zooming, usually without writing
-(void) scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) view
{
NSLog (@ "%s", __func__);
}
3> is scaling, and usually does not need to implement
-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView
{
NSLog (@ "%s", __func__);
NSLog (@ "%@", Nsstringfromcgaffinetransform (Self.imageView.transform));
}
4> to complete the scaling, and usually does not need to implement
-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (cgfloat) scale
{
NSLog (@ "%s", __func__);
}
________________________________________________________________________________________
Run a loop demo
int main (int argc, const char * argv[])
{
@autoreleasepool {
int selection =-1;
while (YES) {
printf ("Please enter a selection, 0 means exit:");
scanf ("%d", &selection);
if (selection = = 0) {
printf ("Welcome to!88\n next time");
Break
} else {
printf ("You have selected%d feature \ n", selection);
}
}
}
return 0;
}
2015/10/3 IOS Note Details iOS9 uialertcontroller simple to use ScrollView Nstimer