iOS 仿今日頭條分享彈窗

2021-08-25 11:15:28 字數 2441 閱讀 5740

效果圖如下所示

原理很簡單,其實就是乙個自定義view, 在建立的時候給每個按鈕新增乙個彈簧動畫,實現此效果.

動畫效果**:

// 這裡遍歷按鈕集合,新增動畫

[self

.btnarray enumerateobjectsusingblock:^(uibutton *button, nsuinteger idx, bool * _nonnull stop) completion:^(bool finished) ];

}];

自定義view,實現布局

#define ylshareviewheight 235.f             // 高度

#define ylshareviewshowduration 0.3f // 動畫時間

@inte***ce ylshareview ()

/// 容器view

@property (nonatomic, strong, readwrite) uiview *contentview;

/// 取消按鈕

@property (nonatomic, strong, readwrite) uibutton *cancelbtn;

/// 背景

@property (nonatomic, strong, readwrite) uiview *bgview;

/// 資料來源

@property (nonatomic, copy, readwrite) nsarray *datasource;

@property (nonatomic, strong, readwrite) nsmutablearray *btnarray;

@property (nonatomic, strong, readwrite) uiscrollview *topscrollview;

@property (nonatomic, strong, readwrite) uiscrollview *bottomscrollview;

/// 分割線

@property (nonatomic, strong, readwrite) uiview *lineview;

@end

@implementation ylshareview

- (instancetype)initwithframe:(cgrect)frame

return self;

}- (void)_initvalues

- (void)_initviews

- (void)layoutsubviews ];

// 容器view

[self.contentview mas_makeconstraints:^(masconstraintmaker *make) ];

[self.topscrollview mas_makeconstraints:^(masconstraintmaker *make) ];

[self.lineview mas_makeconstraints:^(masconstraintmaker *make) ];

[self.bottomscrollview mas_makeconstraints:^(masconstraintmaker *make) ];

}- (void)showshareview ];

}- (void)_dismissshareview completion:^(bool finished) ];

}- (void)_configdata

[self.btnarray enumerateobjectsusingblock:^(uibutton *button, nsuinteger idx, bool * _nonnull stop) completion:^(bool finished) ];

}];self.topscrollview

.contentsize = cgsizemake(height * self.datasource

.count, height);

// self.bottomscrollview

.contentsize = cgsizemake(height * self.datasource

.count, height);

}- (void)touchesbegan:(nsset*)touches withevent:(uievent *)event

- (nsarray *)datasource

return _datasource;

}- (nsmutablearray *)btnarray

return _btnarray;

}

今日頭條面試經驗分享

1.給乙個小頂堆,再給你乙個數,讓你插入到這個堆裡。思路 把這個數放到堆的最後,然後向上調整堆的最後乙個非葉子結點。2.求乙個 字串的 最長回文子串 並且返回第乙個出現的下標。思路 中心擴充套件法,逆序。3.有乙個表,有id,name,age等字段,讓你查詢姓 李 和姓 王 並且年齡 18歲的 記錄...

今日頭條 今日頭條三面面經

一面 1 演算法題,程式設計實現nsum 2 實現元素的居中並且寬高比為3 4 3 實現繼承 4 給了一段 給出輸出結果,這個是和非同步相關 5 http的狀態碼有哪些 6 cookie和session的區別,以及如何生成session 7 給 寫輸出和原型鏈相關 8 變數宣告提公升 三面 1 介紹...

今日頭條筆試

問題描述 給定乙個段落,由 n 個句子組成。第 i 個句子的長度為 l i 包含的單詞個數為 w i 句子不包含任何除字母和空格 外的符號。每個句子內部,含有若干個單詞,由空格 分隔。句子不會包含連續的空格。隨後給定 m 個查詢,每個查詢包含乙個句子,需要在段落中尋找相同單詞數量最多的句子。重複的單...