iPhone と iPad の両方で動作するモジュールを開発しています。このモジュールでは、UIActivityViewController を模倣して、iPhone と iPad の両方でカスタム表示しようとしています。
問題: ポップオーバーが iPad 画面の左上隅に表示されます。ポップアップを表示するボタンはTitanium SDKに作成され、同じボタンをパラメーターとしてモジュールに渡します。モジュールは同じボタンを使用して、特定の位置にポップオーバーを表示します。
以下のコードを確認してください。
チタンコード:
root = {};
var w = Titanium.UI.createWindow({
top : 0,
left : 0,
right : 0,
bottom : 0,
navBarHidden : true,
orientationModes : [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
w.open();
var shareItButton = Titanium.UI.createButton({
top : 10,
right : 40,
width: 90,
height: 30,
backgroundImage : 'images/shareit.png'
});
baseview.add(shareItButton);
// Display Popover when shareItButton is clicked
shareItButton.addEventListener('click', function(e) {
var ShareView = require('com.xyz.sharing');
root.shareController = ShareView.shareViewController; // The proxy controller
root.shareController.shareContent({
message: "Share Message",
url: "http://www.google.com",
title: "Share Title",
file: "File path for iBooks functionality",
shareButton: e.source // e.source is actually a button
});
});
チタン モジュール: com.xyz.sharing
Module.h
#import "TiModule.h"
@interface ComXYZSharingModule : TiModule {
}
- (id) shareViewController;
@end
Module.m
@implementation ComXYZSharingModule
// Ignoring built-in methods, I have pasted only Custom methods
- (id) shareViewController {
ComXYZSharingProxy *proxy = [[ComXYZSharingProxy alloc] init];
proxy.module = self;
return proxy;
}
@end
Proxy.h
@interface ComXYZSharingProxy : TiProxy
@property (nonatomic, strong) ComXYZSharingModule *module;
@property (nonatomic, strong) NSDictionary *content;
@property (strong, nonatomic) TiViewProxy *exportView;
- (void) shareContent : (id) args;
@end
Proxy.m
@implementation ComXYZSharingProxy
- (void) shareContent : (id) args {
ENSURE_UI_THREAD(shareContent, args);
NSArray *val = args;
NSDictionary *dict = [val objectAtIndex: 0];
self.content = dict;
if ([dict objectForKey: @"shareButton"]) {
self.exportView = [dict objectForKey: @"shareButton"]; // This is the Button which gives me wrong values
NSLog(@"Button Found", nil);
NSLog([self.exportView description], nil);
CustomActivityController *controller = [[CustomActivityController alloc] init]; // We have just created the controller which is just customization of UIActivityViewController and that's the main view which will be displayed in Popover for iPad and in modal control for iPhone
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:controller];
//[self setPopoverController:popover];
//[popover setDelegate:self];
[popover setBackgroundColor: [UIColor greenColor]];
popover.popoverContentSize = CGSizeMake(320, 250);
CGRect rect = [TiUtils rectValue: [self.exportView rect]];
NSLog([NSString stringWithFormat: @"Size: x: %f,y: %f, width: %f, height: %f", rect.origin.x, rect.origin.y
, rect.size.width, rect.size.height], nil);
[popover presentPopoverFromRect:rect inView:[[TiApp app] controller].view permittedArrowDirections:arrowDirections animated:animated];
}
}
@end
プログラム実行時の出力
Button Found
Size: x: 0.00,y: 0.00, width: 0.00, height: 0.00 [This should be actual size of Button but somehow it's not]
この問題により、ポップオーバーが iPad 画面の左上隅に表示されます。誰でも問題を解決するのに役立ちますか? TiUIButton または TiUIButtonProxy を使用しようとすると、結果も同じです。