二、自定義友盟分享(強制橫屏)

//便利中間部分時間的子視圖 計算并排不位置

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容