#import "FourViewController.h"
#import "View+masadditions.h"
#import "FiveViewControllerr.h"
#define WS (weakself) __weak __typeof (&*self) weakself = self;
#define Screen_width [UIScreen mainscreen].bounds.size.width
Static nsstring Const*[email protected] "Fourviewcontroller";
Static nsstring Const*[email protected] "Fourviewcontroller";
@interface Fourviewcontroller ()
@property (Strong, nonatomic) UIButton *move;
@property (Strong, nonatomic) UIButton *back;
@property (Strong, nonatomic) Uiimageview *imageview;
@property (assign, nonatomic) int s;
@end
@implementation Fourviewcontroller
+ (Instancetype) Createviewcontrollerwithstoryboard: (ID) createargs{
Uistoryboard *storyboard=[uistoryboard storyboardwithname: (NSString *) Kstoryboardname Bundle:nil];
Fourviewcontroller *vc=[storyboard instantiateviewcontrollerwithidentifier: (NSString *) kIdentifier];
return VC;
}
-(void) Viewdidload {
[Super Viewdidload];
[Self initrightitem];
_s=10;
[Self initfirstcontraints];
}
-(void) initfirstcontraints{
WS (WS);
UIView *view=[uiview New];
View.backgroundcolor=[uicolor Browncolor];
[Self.view Addsubview:view];
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (0);
Make.size.mas_equalTo (Cgsizemake ([UIScreen mainscreen].bounds.size.width,[uiscreen Mainscreen]. Bounds.size.height));
// }];
int width= ([UIScreen mainscreen].bounds.size.width-_s*2-10)/2;
_move=[[uibutton Alloc]init];
_move.backgroundcolor=[uicolor Bluecolor];
[Self.view Addsubview:_move];
[_move mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (100);
Make.width.equalTo (@150);
Make.height.equalTo (@40);
}];
[_move addtarget:self Action: @selector (Moveframe) forcontrolevents:uicontroleventtouchupinside];
[_move settitle:@ "mobile picture" forstate:uicontrolstatenormal];
_back=[[uibutton Alloc]init];
_back.backgroundcolor=[uicolor Greencolor];
[Self.view Addsubview:_back];
[_back mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.right.equalTo (Self.view). With.offset (-_s);
Make.top.equalTo (Self.view). With.offset (100);
Make.width.equalTo (@150);
Make.height.equalTo (@40);
}];
[_back addtarget:self Action: @selector (Backframe) forcontrolevents:uicontroleventtouchupinside];
[_back settitle:@ "picture back" forstate:uicontrolstatenormal];
_imageview=[[uiimageview Alloc]init];
_imageview.image=[uiimage imagenamed:@ "Move"];
[Self.view Addsubview:_imageview];
[_imageview mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) moveframe{
_s=_s+5;;
NSLog (@ "_s:%d", _s);
[_imageview mas_updateconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200+_s);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) backframe{
_s=_s-5;;
NSLog (@ "_s:%d", _s);
[_imageview mas_updateconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Self.view). With.offset (_s);
Make.top.equalTo (Self.view). With.offset (200-_s);
Make.width.equalTo (@150);
Make.height.equalTo (@150);
}];
}
-(void) initrightitem{
[Self settitle:@ "dynamically change control position"];
Uibarbuttonitem *right=[[uibarbuttonitem alloc]initwithtitle:@ "multi-constraint" Style:uibarbuttonitemstyleplain target:self Action: @selector (right)];
Self.navigationitem.rightbarbuttonitem=right;
}
-(void) right{
Fiveviewcontrollerr *vc=[fiveviewcontrollerr Createviewcontrollerwithstoryboard:nil];
[Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS masonry dynamic Constrained control location