我使用此代码在ios上创建本机共享弹出窗口
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/ES3/gl.h>
using namespace share;
@interface ViewController:UIViewController
@end
//----------//----------//----------//----------//----------//----------//
@implementation ViewController
namespace share
{
static ViewController *acController;
BOOL shareSucceed;
BOOL shareFailed;
void shareWithFile(const char *subj, const char *msg, const char *filePath, const char *type)
{
acController = [[ViewController alloc] init];
NSString *subject = [NSString stringWithUTF8String:subj];
NSString *message = [NSString stringWithUTF8String:msg];
NSString *newFilePath = [NSString stringWithUTF8String:filePath];
NSURL *videoLink = [NSURL fileURLWithPath:newFilePath];
NSArray* shareItems = @[message, videoLink];
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[avc setValue:subject forKey:@"subject"];
NSArray *excludeActivities = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo, UIActivityTypePostToWeibo, UIActivityTypeMessage];
avc.excludedActivityTypes = excludeActivities;
id VC = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
NSLog(@"UiPopoverPresentationController for iPad IOS8");
CGFloat width = acController.view.frame.size.width;
CGFloat height = acController.view.frame.size.height;
NSLog(@"%.2f",width);
NSLog(@"%.2f",height);
avc.modalPresentationStyle = UIModalPresentationPopover;
avc.popoverPresentationController.permittedArrowDirections = 0;
avc.popoverPresentationController.sourceRect = CGRectMake(width, height ,1, 1);
avc.popoverPresentationController.sourceView = acController.view;
[VC presentViewController:avc animated:YES completion:nil];
}
bool shareResultSucceed()
{
if (shareSucceed)
{
shareSucceed = NO;
return 1;
}
return 0;
}
bool shareResultFailed()
{
if (shareFailed)
{
shareFailed = NO;
return 1;
}
return 0;
}
}
@end
Popup正在显示,但在不同的设备上有不同的定位。看起来完全忽略了...... sourceRect = CGRectMake(width,height,1,1); 为什么它忽略了定位rect?