php底部弹出选择,iOS 自定义微信分享底部弹出选择界面

//

//  ShareCustom.m

//  HengTaiXinGolf

//

//  Created by 欧阳荣 on 16/3/22.

//  Copyright © 2016年 HengTaiXinGolf. All rights reserved.

//

#import"ShareCustom.h"

#import"WXApi.h"

//设备物理大小

#define kScreenWidth   [UIScreen mainScreen].bounds.size.width

#define kScreenHeight  [UIScreen mainScreen].bounds.size.height

#define SYSTEM_VERSION   [[UIDevice currentDevice].systemVersion floatValue]

//屏幕宽度相对iPhone6屏幕宽度的比例

#define KWidth_Scale    [UIScreen mainScreen].bounds.size.width/640.0f

@implementationShareCustom

staticid_publishContent;//类方法中的全局变量这样用(类型前面加static)

/*

自定义的分享类,使用的是类方法,其他地方只要构造分享内容publishContent就行了

*/

+(void)shareWithContent:(id)publishContent/*只需要在分享按钮事件中 构建好分享内容publishContent传过来就好了*/

{

_publishContent = publishContent;

UIWindow*window = [UIApplicationsharedApplication].keyWindow;

UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];

blackView.backgroundColor = [UIColor colorWithRed:68/255.0 green:68/255.0 blue:68/255.0 alpha:0.85f];

blackView.tag = 440;

[window addSubview:blackView];

UIView*shareView = [[UIViewalloc] initWithFrame:CGRectMake(0,(kScreenHeight-300*KWidth_Scale),IPHONE_WIDTH,300*KWidth_Scale)];

//    shareView.backgroundColor = [UIColor colorWithString:@"f6f6f6"];

shareView.backgroundColor = [UIColor colorWithRed:225/255.0 green:225/255.0 blue:225/255.0 alpha:1.0];

shareView.tag = 441;

[window addSubview:shareView];

NSArray *btnImages = @[@"wxhy", @"wxpyq"];

NSArray *btnTitles = @[@"微信好友", @"微信朋友圈"];

for (NSInteger i=0; i

CGFloat top = 0.0f;

top = 44*KWidth_Scale;

UIButton*button = [[UIButtonalloc] initWithFrame:CGRectMake(138*KWidth_Scale+i*104*KWidth_Scale+158* KWidth_Scale* i, top,104*KWidth_Scale,104*KWidth_Scale)];

[buttonsetImage:[UIImageimageNamed:btnImages[i]]forState:UIControlStateNormal];

UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(128*KWidth_Scale+i*104*KWidth_Scale+158* KWidth_Scale* i, top + (104+12)*KWidth_Scale,124*KWidth_Scale,28* KWidth_Scale)];

label.text = btnTitles[i];

label.font = [UIFont systemFontOfSize:22*KWidth_Scale];

label.textColor = [UIColor colorWithRed:138/255.0 green:138/255.0 blue:138/255.0 alpha:1.0];

label.textAlignment=NSTextAlignmentCenter;

[shareView addSubview:label];

//        [button setTitle:btnTitles[i] forState:UIControlStateNormal];

//        button.titleLabel.font = [UIFont systemFontOfSize:22*KWidth_Scale];

//        button.titleLabel.textAlignment = NSTextAlignmentCenter;

//        [button setTitleColor:[UIColor colorWithRed:138/255.0 green:138/255.0 blue:138/255.0 alpha:1.0] forState:UIControlStateNormal];

//        [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];

//        [button setContentVerticalAlignment:UIControlContentVerticalAlignmentTop];

// button.frame = CGRectMake(100, 100,90, 90);//button的frame

//        button.imageEdgeInsets = UIEdgeInsetsMake(5,13,21,button.titleLabel.bounds.size.width);//设置image在button上的位置(上top,左left,下bottom,右right)这里可以写负值,对上写-5,那么image就象上移动5个像素

//        button.titleEdgeInsets = UIEdgeInsetsMake(71, -button.titleLabel.bounds.size.width-50, 0, 0);//设置title在button上的位置(上top,左left,下bottom,右right)

//我这里使用的image是64*64的

//        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//设置button的内容横向居中。。设置content是title和image一起变化

//

//        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 15.5*KWidth_Scale, 31*KWidth_Scale, button.titleLabel.bounds.size.width)];

//        if (SYSTEM_VERSION >= 8.0f) {

//            [button setTitleEdgeInsets:UIEdgeInsetsMake(129*KWidth_Scale,- button.titleLabel.bounds.size.width-100*KWidth_Scale*2, 0, 0)];

//        }else{

//            [button setTitleEdgeInsets:UIEdgeInsetsMake(129*KWidth_Scale,- button.titleLabel.bounds.size.width-100*KWidth_Scale*2, 0, 0)];

//        }

button.tag = 331+i;

[buttonaddTarget:selfaction:@selector(shareBtnClick:)forControlEvents:UIControlEventTouchUpInside];

[shareView addSubview:button];

}

UIButton *cancleBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, shareView.frame.size.height-80*KWidth_Scale,IPHONE_WIDTH, 80*KWidth_Scale)];

//    [cancleBtn setBackgroundImage:[UIImage imageNamed:@"IOS-取消@2x.png"] forState:UIControlStateNormal];

cancleBtn.tag = 339;

[cancleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

cancleBtn.backgroundColor = kColor(246, 246, 246);

[cancleBtn setTitle:@"取消" forState:UIControlStateNormal];

[cancleBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];

[shareView addSubview:cancleBtn];

//为了弹窗不那么生硬,这里加了个简单的动画

//    shareView.transform = CGAffineTransformMakeScale(1/300.0f, 1/270.0f);

//    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];

shareView.frame = CGRectMake(0,kScreenHeight, IPHONE_WIDTH, 300*KWidth_Scale);

;

blackView.alpha = 0;

[UIView animateWithDuration:0.35f animations:^{

//        shareView.transform = CGAffineTransformMakeScale(1, 1);

shareView.frame = CGRectMake(0,(kScreenHeight-300*KWidth_Scale), IPHONE_WIDTH, 300*KWidth_Scale);

blackView.alpha = 1;

} completion:^(BOOL finished) {

}];

}

+(void)shareBtnClick:(UIButton *)btn

{

//    NSLog(@"%@",[ShareSDK version]);

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UIView *blackView = [window viewWithTag:440];

UIView *shareView = [window viewWithTag:441];

//为了弹窗不那么生硬,这里加了个简单的动画

//    shareView.transform = CGAffineTransformMakeScale(1, 1);

[UIView animateWithDuration:0.35f animations:^{

//        shareView.transform = CGAffineTransformMakeScale(1/300.0f, 1/270.0f);

blackView.alpha = 0;

shareView.frame = CGRectMake(0,kScreenHeight, IPHONE_WIDTH, 300*KWidth_Scale);

} completion:^(BOOL finished) {

[shareView removeFromSuperview];

[blackView removeFromSuperview];

}];

int shareType = 0;

id publishContent = _publishContent;

switch (btn.tag) {

case 331:

{

//            shareType = ShareTypeWeixiSession;

DSLog(@"微信好友");

SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];

req.text = @"这是测试发送的内容。";

req.bText = YES;

req.scene = WXSceneSession;

[WXApi sendReq:req];

}

break;

case 332:

{

DSLog(@"微信朋友圈");

//            shareType = ShareTypeWeixiTimeline;

}

break;

case 339:

{

DSLog(@"取消");

}

break;

default:

break;

}

/*

调用shareSDK的无UI分享类型,

*/

//    [ShareSDK showShareViewWithType:shareType container:nil content:publishContent statusBarTips:YES authOptions:nil shareOptions:nil result:^(ShareType type, SSResponseState state, id statusInfo, id error, BOOL end) {

//        if (state == SSResponseStateSuccess)

//        {

//            //            NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));

//        }

//        else if (state == SSResponseStateFail)

//        {

//            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"" message:@"未检测到客户端 分享失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

//            [alert show];

//            //            NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);

//        }

//    }];

}

//

构造分享内容

//id publishContent = [ShareSDK content:str1

//                                   defaultContent:str1

//                                            image:nil

//                                            title:@" "

//                                              url:urlString

//                                      description:str1

//                                        mediaType:SSPublishContentMediaTypeText];

调用自定义分享

//[ShareCustom shareWithContent:publishContent];

//

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS开发中,使用Swift可以实现底部弹出视图。以下是一个简单的实现方式: 首先,需要创建一个底部弹出视图的ViewController。可以在Storyboard中创建一个新的ViewController,并设置其底部约束为屏幕底部,高度为底部弹出视图的高度。可以在该ViewController中添加需要显示的内容,比如按钮、标签等。 然后,在需要弹出底部视图的地方,可以通过 present 方法来显示这个ViewController。可以在当前的ViewController中添加一个按钮,当点击该按钮时,调用如下代码来显示底部弹出视图: ```swift // 创建底部弹出视图的ViewController let bottomViewController = storyboard?.instantiateViewController(withIdentifier: "BottomViewController") as! BottomViewController // 设置底部弹出视图的 ModalPresentationStyle 为 .overCurrentContext,使得弹出视图会覆盖当前视图 bottomViewController.modalPresentationStyle = .overCurrentContext // 设置底部弹出视图的 TransitioningDelegate;通过实现相关代理方法来自定义弹出视图的动画效果 bottomViewController.transitioningDelegate = self // 弹出底部视图 present(bottomViewController, animated: true, completion: nil) ``` 在当前ViewController中,需要增加一个扩展来实现底部弹出视图的自定义动画: ```swift extension ViewController: UIViewControllerTransitioningDelegate { // 返回自定义的动画控制器对象 func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return BottomViewAnimator(isPresenting: true) } // 返回自定义的动画控制器对象 func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return BottomViewAnimator(isPresenting: false) } } ``` 在自定义动画控制器中,可以实现底部弹出视图的动画效果。可以通过使用 UIView 的动画方法来实现位移、透明度等动画效果。 最后,需要创建一个自定义的 Animator 类,实现 UIViewControllerAnimatedTransitioning 协议的相关代理方法来控制动画的展示和隐藏。 通过上述步骤,即可完成iOS底部弹出视图的实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值