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

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

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值

//計算視圖沒執(zhí)行動畫之前的y值

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

[self.hiddenBtnYArray addObject:@(hiddenY)];//保存沒執(zhí)行動畫之前的y值

btn.frame=CGRectMake(viewX,hiddenY,width,height); //賦值沒執(zhí)行動畫之前視圖的位置

}

//執(zhí)行動畫

[self animationsToBtn];

}

//執(zhí)行顯示時動畫的方法

-(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(), ^{

//執(zhí)行動畫 并且顯示到最終的位置

[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);

//

//? ? ? ? ? ? ? ? ? ? ? ? ? ? }];

//

//? ? ? ? ? ? ? ? ? ? ? ? });

});

});

});

});

});

}

//二裙顽、調(diào)用(在哪個控制器里面需要調(diào)用付燥,就寫在那個)

EG:點擊按鈕的時候

//得到appdelegate的單列對象

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

//實例化封面對象 并且添加到窗體中去

CoverView *cover=[CoverView coverView];

[app.window addSubview:cover];

//去掉系統(tǒng)的布局? 手動布局

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;

三、以上的舉例是添加到系統(tǒng)頁面上的愈犹、如果是當前控制器键科、就把

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

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末漩怎,一起剝皮案震驚了整個濱河市勋颖,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌勋锤,老刑警劉巖饭玲,帶你破解...
    沈念sama閱讀 217,084評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異叁执,居然都是意外死亡茄厘,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評論 3 392
  • 文/潘曉璐 我一進店門徒恋,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蚕断,“玉大人,你說我怎么就攤上這事入挣∫谌椋” “怎么了?”我有些...
    開封第一講書人閱讀 163,450評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長葛假。 經(jīng)常有香客問我障陶,道長,這世上最難降的妖魔是什么聊训? 我笑而不...
    開封第一講書人閱讀 58,322評論 1 293
  • 正文 為了忘掉前任抱究,我火速辦了婚禮,結(jié)果婚禮上带斑,老公的妹妹穿的比我還像新娘鼓寺。我一直安慰自己,他們只是感情好勋磕,可當我...
    茶點故事閱讀 67,370評論 6 390
  • 文/花漫 我一把揭開白布妈候。 她就那樣靜靜地躺著,像睡著了一般挂滓。 火紅的嫁衣襯著肌膚如雪苦银。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,274評論 1 300
  • 那天赶站,我揣著相機與錄音幔虏,去河邊找鬼。 笑死贝椿,一個胖子當著我的面吹牛想括,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播团秽,決...
    沈念sama閱讀 40,126評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼主胧,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了习勤?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,980評論 0 275
  • 序言:老撾萬榮一對情侶失蹤焙格,失蹤者是張志新(化名)和其女友劉穎图毕,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體眷唉,經(jīng)...
    沈念sama閱讀 45,414評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡予颤,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,599評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了冬阳。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蛤虐。...
    茶點故事閱讀 39,773評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖肝陪,靈堂內(nèi)的尸體忽然破棺而出驳庭,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 35,470評論 5 344
  • 正文 年R本政府宣布饲常,位于F島的核電站蹲堂,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏贝淤。R本人自食惡果不足惜柒竞,卻給世界環(huán)境...
    茶點故事閱讀 41,080評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望播聪。 院中可真熱鬧朽基,春花似錦、人聲如沸离陶。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽枕磁。三九已至渡蜻,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間计济,已是汗流浹背茸苇。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留沦寂,地道東北人学密。 一個月前我還...
    沈念sama閱讀 47,865評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像传藏,于是被迫代替她去往敵國和親腻暮。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,689評論 2 354

推薦閱讀更多精彩內(nèi)容