此方法 可以将子视图绑定再父视图范围之类!
警告:
这里要注意的是,子视图的frame的size要比父视图的要小!!!!
/**
* 让子视图一直在父视图范围之类 子视图的frame的size要比父视图的要小!!!
*
* @param view 子视图
*/
+ (void)makeViewInSuper:(UIView *)view{
CGFloat x = view.frame.origin.x;
CGFloat y = view.frame.origin.y;
CGFloat w = view.frame.size.width;
CGFloat h = view.frame.size.height;
CGFloat gap = 5.00;
if (x < 0 && y < 0) {
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(gap, gap , w, h);
}];
}else if (x + w > view.superview.bounds.size.width && y + h > view.superview.bounds.size.height){
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(view.superview.bounds.size.width - w - gap, view.superview.bounds.size.height - h -gap , w, h);
}];
}else if (x < 0 && y + h > view.superview.bounds.size.height) {
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(gap, view.superview.bounds.size.height - h -gap , w, h);
}];
}else if (x + w > view.superview.bounds.size.width && y < 0){
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(view.superview.bounds.size.width - w - gap, gap, w, h);
}];
}else if (x < 0) {
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(gap, y , w, h);
}];
}else if (x + w > view.superview.bounds.size.width){
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(view.superview.bounds.size.width - w - gap, y, w, h);
}];
}else if (y < 0 ) {
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(x, gap, w, h);
}];
}else if (y + h > view.superview.bounds.size.height){
[UIView animateWithDuration:0.5 animations:^{
view.frame = CGRectMake(x, view.superview.bounds.size.height - h - gap , w, h);
}];
}
}