日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

iOS 类似复制链接打开淘宝APP后弹出页面功能

發(fā)布時(shí)間:2023/12/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS 类似复制链接打开淘宝APP后弹出页面功能 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

寫(xiě)在前面

我們應(yīng)該都有用過(guò)這個(gè)功能,你的朋友微信給你分享了一個(gè)淘寶里面的商品鏈接,然后當(dāng)你復(fù)制這個(gè)鏈接打開(kāi)淘寶APP的時(shí)候,就會(huì)彈出一個(gè)彈窗,像這樣:

example.PNG

這個(gè)功能想必大家都挺熟悉,受這個(gè)啟發(fā)我們產(chǎn)品也想在我們APP上添加這樣一個(gè)功能,與這個(gè)不一樣的是,當(dāng)我們復(fù)制一段網(wǎng)址的時(shí)候打開(kāi)我們的APP會(huì)彈出框填一些信息后上傳到我們的“資源庫(kù)”。大體功能就這樣,所以記錄一下實(shí)現(xiàn)的過(guò)程。

一、彈窗視圖功能

.h中:兩個(gè)信號(hào)一個(gè)是確定信號(hào)一個(gè)是取消信號(hào)

兩個(gè)方法,一個(gè)顯示一個(gè)隱藏方法

12345@property?(nonatomic,?strong)?RACSubject?*uploadSureSignal;//確定上傳信號(hào)@property?(nonatomic,?strong)?RACSubject?*hideSucSignal;//隱藏-?(void)show;-?(void)hide;

.m中:主要是兩個(gè)textview,還有涉及到在keywindow上,IQKeyboard的一些操作

123@property?(nonatomic,?assign)?CGFloat?keyboardHeight;//鍵盤(pán)高度@property?(nonatomic,?strong)?CustomUITextView?*nameTV;@property?(nonatomic,?strong)?CustomUITextView?*desTV;

因?yàn)榘l(fā)現(xiàn)IQKeyboard在這個(gè)彈出界面有問(wèn)題,所以在顯示這個(gè)界面的時(shí)候,將IQKeyboard禁用取之使用系統(tǒng)的keyboard監(jiān)聽(tīng)方法

在(void)show方法中:

12345678-(void)show?{//鍵盤(pán)通知????NSNotificationCenter?*defaultCenter?=?[NSNotificationCenter?defaultCenter];?????????[defaultCenter?addObserver:self?selector:@selector(keyboardWillShowOrHide:)?name:UIKeyboardWillShowNotification?object:nil];?????????[defaultCenter?addObserver:self?selector:@selector(keyboardWillShowOrHide:)?name:UIKeyboardWillHideNotification?object:nil];}
123456789101112131415161718192021222324252627282930//監(jiān)聽(tīng)方法-?(void)keyboardWillShowOrHide:(NSNotification?*)notification?{????//獲取通知名????NSString?*notificationName?=?notification.name;????//獲取通知內(nèi)容????NSDictionary?*keyboardInfo?=?notification.userInfo;????//鍵盤(pán)彈出時(shí),讓畫(huà)面整體稍稍上移,并伴隨動(dòng)畫(huà)????//鍵盤(pán)回收時(shí)反之????CGRect?keyboardFrame?=?[notification.userInfo[UIKeyboardFrameEndUserInfoKey]?CGRectValue];????CGFloat?height?=?keyboardFrame.size.height;????self.keyboardHeight?=?height;????//動(dòng)畫(huà)結(jié)束后self.view的frame值????CGRect?selfViewFrame?=?self.bgView.frame;????//通過(guò)通知名字判斷彈出還是回收????if?([notificationName?isEqualToString:UIKeyboardWillShowNotification])?{????????selfViewFrame.origin.y?=?SCREEN_HEIGHT?-?PANELHEIGHT?-?height;????}?else?{????????selfViewFrame.origin.y?=?SCREEN_HEIGHT?-?PANELHEIGHT;????}?????????//取出動(dòng)畫(huà)時(shí)長(zhǎng)????NSTimeInterval?duration?=?[keyboardInfo[UIKeyboardAnimationDurationUserInfoKey]?doubleValue];?????????//使用動(dòng)畫(huà)更改self.view.frame????[UIView?animateWithDuration:duration?animations:^{????????//這里填入一些view的最終狀態(tài)屬性設(shè)置,即會(huì)自動(dòng)產(chǎn)生過(guò)渡動(dòng)畫(huà)????????self.bgView.frame?=?selfViewFrame;????}];?????}

同時(shí)在show方法中顯示keyWindow,進(jìn)而改變界面的frame進(jìn)行顯示

12345678910-?(void)show?{UIWindow?*keyWindow?=?[UIApplication?sharedApplication].keyWindow;????[keyWindow?addSubview:self];????CGRect?frame?=?self.bgView.frame;????if?(frame.origin.y?==?SCREEN_HEIGHT)?{????????frame.origin.y?=?SCREEN_HEIGHT?-?PANELHEIGHT;????????[UIView?animateWithDuration:0.4?animations:^{????????????self.bgView.frame?=?frame;????????}];????}

hide方法這里要考慮到鍵盤(pán)彈出后將self.bgView向上提高后frame的變化。

12345678910111213CGRect?selfFrame?=?self.bgView.frame;????if?(selfFrame.origin.y?==?SCREEN_HEIGHT?-?PANELHEIGHT?||?selfFrame.origin.y?==?SCREEN_HEIGHT?-?PANELHEIGHT?-?self.keyboardHeight)?{????????[self?resignFirstResponder];????????selfFrame.origin.y?=?SCREEN_HEIGHT;????????[UIView?animateWithDuration:0.4?animations:^{????????????self.bgView.frame?=?selfFrame;????????}?completion:^(BOOL?finished)?{????????????[IQKeyboardManager?sharedManager].enable?=?YES;????????????[[NSNotificationCenter?defaultCenter]?removeObserver:self];//????????????[self.hideSucSignal?sendNext:nil];????????????[self?removeFromSuperview];????????}];????}

delegate中的操作

這里首先要弄懂APPdelegate中的這幾個(gè)代理方法的意思:

1234567891011121314151617181920212223242526272829303132//App已經(jīng)啟動(dòng)-?(BOOL)application:(UIApplication?*)application?didFinishLaunchingWithOptions:(NSDictionary?*)launchOptions?{????//?Override?point?for?customization?after?application?launch.????return?YES;}//App掛起狀態(tài)-?(void)applicationWillResignActive:(UIApplication?*)application?{????//?Sent?when?the?application?is?about?to?move?from?active?to?inactive?state.?This?can?occur?for?certain?types?of?temporary?interruptions?(such?as?an?incoming?phone?call?or?SMS?message)?or?when?the?user?quits?the?application?and?it?begins?the?transition?to?the?background?state.????//?Use?this?method?to?pause?ongoing?tasks,?disable?timers,?and?invalidate?graphics?rendering?callbacks.?Games?should?use?this?method?to?pause?the?game.}//APP進(jìn)入后臺(tái)-?(void)applicationDidEnterBackground:(UIApplication?*)application?{????//?Use?this?method?to?release?shared?resources,?save?user?data,?invalidate?timers,?and?store?enough?application?state?information?to?restore?your?application?to?its?current?state?in?case?it?is?terminated?later.????//?If?your?application?supports?background?execution,?this?method?is?called?instead?of?applicationWillTerminate:?when?the?user?quits.}//APP將重新回到前臺(tái)-?(void)applicationWillEnterForeground:(UIApplication?*)application?{????//?Called?as?part?of?the?transition?from?the?background?to?the?active?state;?here?you?can?undo?many?of?the?changes?made?on?entering?the?background.}//APP進(jìn)入活躍狀態(tài)-?(void)applicationDidBecomeActive:(UIApplication?*)application?{????//?Restart?any?tasks?that?were?paused?(or?not?yet?started)?while?the?application?was?inactive.?If?the?application?was?previously?in?the?background,?optionally?refresh?the?user?interface.}//系統(tǒng)時(shí)間發(fā)生改變時(shí)執(zhí)行-?(void)applicationWillTerminate:(UIApplication?*)application?{????//?Called?when?the?application?is?about?to?terminate.?Save?data?if?appropriate.?See?also?applicationDidEnterBackground:.}

在上面的這些代理方法中,我們需要用到的是 ?applicationDidBecomeActive方法。在這個(gè)方法中我們?nèi)z查系統(tǒng)的粘貼板UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

123456789101112131415161718192021222324252627if?(pasteboard.string)?{????????????NSLog(@"string:%@",?pasteboard.string);????????????NSString?*urlStr?=?pasteboard.string;????????????if?([urlStr?hasPrefix:@"https://"]?||?[urlStr?hasPrefix:@"http://"])?{//如果粘貼板中的字符串包含https或http字段,我們?nèi)z查當(dāng)前的控制器?如果當(dāng)前的控制器是我們彈出做操作的控制器的話?isPopVC?=?NO;????????????????BOOL?isPopVC?=?NO;????????????????UIViewController?*?Rootvc?=?self.window.rootViewController;????????????????if?([Rootvc?isKindOfClass:[UINavigationController?class]])?{????????????????????UINavigationController?*?nav?=?(UINavigationController?*)Rootvc;????????????????????UIViewController?*?v?=?[nav.viewControllers?lastObject];????????????????????if?([v?isKindOfClass:[UploadResCofingVC?class]])?{????????????????????????isPopVC?=?YES;????????????????????}????????????????}????????????????//如果popView?==?nil?并且isPopVC?==?NO?彈出popView彈窗視圖?進(jìn)行操作????????????????if?(!self.popView?&&?!isPopVC)?{????????????????????UploadResourcesPopupView?*popView?=?[UploadResourcesPopupView?new];????????????????????[popView?show];????????????????????self.popView?=?popView;????????????????????[self.popView.hideSucSignal?subscribeNext:^(id?x)?{????????????????????????@strongify(self);????????????????????????self.popView?=?nil;????????????????????}];????????????????}????????????}????????}????}

總結(jié)

以上大體就是實(shí)現(xiàn)這個(gè)功能的基本思路,細(xì)節(jié)方面因項(xiàng)目而異了,比如我們需要判斷當(dāng)前用戶的角色,當(dāng)前用戶是否登錄,對(duì)彈窗視圖后續(xù)的一些操作。當(dāng)然并不完美,歡迎批評(píng)指正。

收藏

總結(jié)

以上是生活随笔為你收集整理的iOS 类似复制链接打开淘宝APP后弹出页面功能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。