iOS masonry动态约束控件位置
来源:互联网 发布:网络售卖病假条 编辑:程序博客网 时间:2024/06/05 05:04
#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*kStoryboardName=@"FourViewController";
static NSString const*kIdentifier=@"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:@"移动图片" 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:@"图片回来" 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:@"动态改变控件位置"];
UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"多约束" 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];
}
- iOS masonry动态约束控件位置
- Android动态添加控件约束位置
- iOS-使用代码约束布局(Masonry)
- iOS Masonry(约束)的基本使用
- iOS开发- Masonry约束第三方详解
- iOS学习之Masonry第三方约束
- Masonry约束
- 利用masonry添加约束的控件, 添加部分圆角
- 关于masonry 使用中多次改变一个控件的约束
- iOS 动态改变约束
- iOS - 使用"Masonry"库做约束(自动布局)
- iOS--Masonry解决 tableViewCell 重用时约束冲突
- 【iOS自动约束】使用Masonry导致内存持续增长问题分析
- iOS开发masonry动态布局cell高度
- Masonry — 代码约束
- masonry 约束布局
- Masonry约束的使用
- masonry延时约束bug
- ListView 中嵌套了OnClickListener事件,而本身onItemClick事件无响应的解决方案
- Map.putAll方法——追加另一个Map对象到当前Map集合
- 设计模式
- JAVA学习(一):Java介绍及其平台、开发环境的配置与搭建
- github简单使用教程_GOOD
- iOS masonry动态约束控件位置
- OpenvSwitch完全使用手册
- JavaCard开发环境搭建
- 浮点数转字符串函数fcvt和gcvt
- Guice 学习(四)基本属性注入(Field Inject)
- Qt第三方库QCustomPlot——认识图表的各个部分
- Stratgy策略模式
- soap讲解
- 在Eclipse中配置Tomcat7.0