美文网首页
二、自定义友盟分享(强制横屏)

二、自定义友盟分享(强制横屏)

作者: 再也不要见 | 来源:发表于2016-08-04 16:47 被阅读0次

//便利中间部分时间的子视图 计算并排不位置

for (int i=0;i<self.containerView.subviews.count;i++){

UIButton *btn=self.containerView.subviews[i];

int colIndex=i%colums; //列的索引

int rowIndex=i/colums; //行的索引

CGFloat viewX=marginLeft+colIndex*(marginX+width);//视图x的计算

CGFloat viewY=marginTop+rowIndex*(marginY+height);//视图y的计算

[self.btnYArray addObject:@(viewY)];//保存视图真实的y值

//计算视图没执行动画之前的y值

CGFloat hiddenY=viewY+CGRectGetHeight(self.containerView.frame)+self.frame.size.height-CGRectGetMaxY(self.containerView.frame);

[self.hiddenBtnYArray addObject:@(hiddenY)];//保存没执行动画之前的y值

btn.frame=CGRectMake(viewX,hiddenY,width,height); //赋值没执行动画之前视图的位置

}

//执行动画

[self animationsToBtn];

}

//执行显示时动画的方法

-(void)animationsToBtn{

dt=[NSUserDefaults standardUserDefaults];

[dt setObject:@(0) forKey:@"showORno"];

[dt synchronize];

UIButton *btn=self.containerView.subviews[0];//取到视图  按钮

CGFloat showY=[self.btnYArray[0] floatValue]; //取到视图真实的y坐标

dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

dispatch_after(time, dispatch_get_main_queue(), ^{

//执行动画 并且显示到最终的位置

[UIView animateWithDuration:1.0 animations:^{

btn.frame=CGRectMake(btn.frame.origin.x, showY, btn.frame.size.width, btn.frame.size.height);

}];

UIButton *btn1=self.containerView.subviews[1];

CGFloat showY1=[self.btnYArray[1] floatValue];

dispatch_time_t time1 = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

dispatch_after(time1, dispatch_get_main_queue(), ^{

[UIView animateWithDuration:1.0 animations:^{

btn1.frame=CGRectMake(btn1.frame.origin.x, showY1, btn1.frame.size.width, btn1.frame.size.height);

}];

UIButton *btn2=self.containerView.subviews[2];

CGFloat showY2=[self.btnYArray[2] floatValue];

dispatch_time_t time2 = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

dispatch_after(time2, dispatch_get_main_queue(), ^{

[UIView animateWithDuration:1.0 animations:^{

btn2.frame=CGRectMake(btn2.frame.origin.x, showY2, btn2.frame.size.width, btn2.frame.size.height);

}];

UIButton *btn3=self.containerView.subviews[3];

CGFloat showY3=[self.btnYArray[3] floatValue];

dispatch_time_t time3 = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

dispatch_after(time3, dispatch_get_main_queue(), ^{

[UIView animateWithDuration:1.0 animations:^{

btn3.frame=CGRectMake(btn3.frame.origin.x, showY3, btn3.frame.size.width, btn3.frame.size.height);

}];

UIButton *btn4=self.containerView.subviews[4];

CGFloat showY4=[self.btnYArray[4] floatValue];

dispatch_time_t time4 = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

dispatch_after(time4, dispatch_get_main_queue(), ^{

[UIView animateWithDuration:1.0 animations:^{

btn4.frame=CGRectMake(btn4.frame.origin.x, showY4, btn4.frame.size.width, btn4.frame.size.height);

}];

//                        UIButton *btn5=self.containerView.subviews[5];

//

//                        CGFloat showY5=[self.btnYArray[5] floatValue];

//

//                        dispatch_time_t time5 = dispatch_time(DISPATCH_TIME_NOW, (NSInteger)(0.02 * NSEC_PER_SEC));

//                        dispatch_after(time5, dispatch_get_main_queue(), ^{

//

//                            [UIView animateWithDuration:1.0 animations:^{

//

//                                btn5.frame=CGRectMake(btn5.frame.origin.x, showY5, btn5.frame.size.width, btn5.frame.size.height);

//

//                            }];

//

//                        });

});

});

});

});

});

}

//二、调用(在哪个控制器里面需要调用,就写在那个)

EG:点击按钮的时候

//得到appdelegate的单列对象

AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;

//实例化封面对象 并且添加到窗体中去

CoverView *cover=[CoverView coverView];

[app.window addSubview:cover];

//去掉系统的布局  手动布局

cover.translatesAutoresizingMaskIntoConstraints=NO;

NSLayoutConstraint *top=[NSLayoutConstraint constraintWithItem:cover attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:app.window attribute:NSLayoutAttributeTop multiplier:1 constant:0];

NSLayoutConstraint *left=[NSLayoutConstraint constraintWithItem:cover attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:app.window  attribute:NSLayoutAttributeLeft multiplier:1 constant:0];

NSLayoutConstraint *right=[NSLayoutConstraint constraintWithItem:cover attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:app.window  attribute:NSLayoutAttributeRight multiplier:1 constant:0];

NSLayoutConstraint *bottom=[NSLayoutConstraint constraintWithItem:cover attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:app.window  attribute:NSLayoutAttributeBottom multiplier:1 constant:0];

top.active=YES;

left.active=YES;

right.active=YES;

bottom.active=YES;

三、以上的举例是添加到系统页面上的、如果是当前控制器、就把

AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;

注释、把所有的app.window修改成self.view

相关文章

  • 二、自定义友盟分享(强制横屏)

    //便利中间部分时间的子视图 计算并排不位置 for (int i=0;i

  • 一、自定义友盟分享(强制横屏)

    EG:基本的分享:微信、微博、QQ、QQZone、新浪微博 一、创建背景的模糊视图,以及一个页面的6个按钮 1、分...

  • 横竖屏

    需求: 让push的ViewController界面强制横屏 一、配置 二、添加强制横屏方法 pragma mar...

  • iOS:强制横屏的坑

    前段时间我们播放器强制横屏,项目设置允许竖屏,在手机不锁屏状态下,手机横屏会导致播放器强制横屏的时候会导致横屏失败...

  • iOS强制横屏

    iOS强制横屏

  • 强制横屏方法

    强制横屏: 方法一: 关于强制横屏看了很多文章,首先第一个方法是invocation,这个方法可以实现横屏效果,但...

  • 强制横屏

    转载自 :http://blog.csdn.net/zhaotao0617/article/details/525...

  • 强制横屏

    -(void)landscapeAndPortraitChange{UIInterfaceOrientation ...

  • 强制横屏

    1、AppDelegate里设置属性 @property(nonatomic,assign)BOOLallowLa...

  • iOS强制横屏方法之一

    //这段代码是强制产生横屏效果,通过kvo实现//强制右横屏 可以过审核-(void)viewWillAppea...

网友评论

      本文标题:二、自定义友盟分享(强制横屏)

      本文链接:https://www.haomeiwen.com/subject/clocsttx.html