Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOs定位上的本机共享弹出窗口_Ios_Objective C_Popup - Fatal编程技术网

iOs定位上的本机共享弹出窗口

iOs定位上的本机共享弹出窗口,ios,objective-c,popup,Ios,Objective C,Popup,我正在用这段代码在ios上创建本机共享弹出窗口 #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #import <OpenGLES/ES3/gl.h> using namespace share; @interface ViewController:UIViewController @end //----------//----------//----------//----------

我正在用这段代码在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
#导入
#进口
#进口
使用名称空间共享;
@界面ViewController:UIViewController
@结束
//----------//----------//----------//----------//----------//----------//
@实现视图控制器
命名空间共享
{
静态视图控制器*自动控制器;
布尔分享成功;
布尔共享失败;
void shareWithFile(常量字符*subc,常量字符*msg,常量字符*文件路径,常量字符*类型)
{
acController=[[ViewController alloc]init];
NSString*subject=[nsstringwithutf8string:subc];
NSString*消息=[NSString stringWithUTF8String:msg];
NSString*newFilePath=[NSString stringWithUTF8String:filePath];
NSURL*videoLink=[NSURL fileURLWithPath:newFilePath];
NSArray*shareItems=@[消息,视频链接];
UIActivityViewController*avc=[[UIActivityViewController alloc]initWithActivityItems:shareItems应用程序活动:nil];
[avc setValue:subject forKey:@“subject”];
NSArray*excludeActivities=@[UIActivityTypePrint、UIActivityTypeCopyToPasteboard、UIActivityTypeAssignToContact、UIActivityTypeAddToRadingList、UIActivityTypePostToBlicker、UIActivityTypePostToVimeo、UIActivityTypePostToTencentWeibo、UIActivityTypePostToWebo、UIActivityTypeMessage];
avc.ExcludeDactivitypes=excludeActivities;
id VC=[UIApplication sharedApplication]键窗口]子视图]对象索引:0]下一个响应者];
NSLog(@“用于iPad IOS8的UiPopoverPresentationController”);
CGFloat width=acontroller.view.frame.size.width;
CGFloat height=acontroller.view.frame.size.height;
NSLog(@“%.2f”,宽度);
NSLog(@“%.2f”,高度);
avc.modalPresentationStyle=UIModalPresentationPopover;
avc.popoverPresentationController.permittedArrowDirections=0;
avc.popopresentationcontroller.sourceRect=CGRectMake(宽度、高度,1,1);
avc.popoverPresentationController.sourceView=acontroller.view;
[VC presentViewController:avc动画:是完成:无];
}
bool sharesultsucceed()
{
如果(成功)
{
ShareSuccess=否;
返回1;
}
返回0;
}
bool sharesultfailed()
{
如果(共享失败)
{
shareFailed=否;
返回1;
}
返回0;
}
}
@结束
弹出窗口正在显示,但在不同设备上的位置不同。看起来它完全忽略了…sourceRect=CGRectMake(宽度,高度,1,1);
为什么它忽略了定位矩形?

CGRectMake不是应该是(x,y,宽度,高度)吗?而不是(宽度、高度、x、y)?除了按正确的顺序放置
CGRectMake
参数外,还要注意
sourceRect
不应是整个视图。它应该是它的一小部分,例如用于特定按钮或其他小部件。尝试使用avc.popopresentationcontroller.sourceRect=CGRectMake(200150300300);,但它仍然在错误的位置。基于sourceRect的定位仍然没有效果。CGRectMake不是应该是(x,y,width,height)吗?而不是(宽度、高度、x、y)?除了按正确的顺序放置
CGRectMake
参数外,还要注意
sourceRect
不应是整个视图。它应该是它的一小部分,例如用于特定按钮或其他小部件。尝试使用avc.popopresentationcontroller.sourceRect=CGRectMake(200150300300);,但它仍然在错误的位置。基于sourceRect的定位仍然没有效果。