我正在使用 UIWebView 将 SVG 图像叠加到一些标准的 iOS UI 上。在我的
我正在使用 SVG 提供底层 UI 的“游览”。我仍然
正在处理这个问题,所以我有一些未解决的问题。
- SVG 动画似乎没有
工作,虽然我可能会成为
错在这。
- 我只使用了简单的 SVG,没有
链接到 .CSS 样式表或其他
文件。
- 我正在使用一个派生自
UIWebView,并让它覆盖
整个表面。你可以
可能有一个较小的 UIWebView,
但我没有尝试过。
- 这是一个简单的 SVG 示例
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
id="tutorialLayout" width="480px" height="320px">
<desc>UI Feature</desc>
<defs>
<rect id="cover" width="480px" height="320px" opacity="0.3" fill="black"/>
</defs>
<g>
<rect id="top" x="000px" y="000px" width="480px" height="290px" opacity="0.3" fill="black"/>
<rect id="bottom" x="000px" y="310px" width="480px" height="010px" opacity="0.3" fill="black"/>
<rect id="left" x="000px" y="290px" width="010px" height="020px" opacity="0.3" fill="black"/>
<rect id="right" x="200px" y="290px" width="280px" height="020px" opacity="0.3" fill="black"/>
<text x="10" y="280" alignment-baseline="bottom"
style="font-size:32; font-family:Arial fill:black;"
>The totals are reported here</text>
</g>
</svg>
5) 这是加载 SVG 的代码片段
NSBundle *bundle = [NSBundle mainBundle];
NSString *svg = @"svg";
[svgView_ addRequest: [NSURL URLWithString: [bundle pathForResource: @"Arrow" ofType: svg ]] seconds: 5];
[svgView_ addRequest: [NSURL URLWithString: [bundle pathForResource: @"t_help" ofType: svg ]] seconds: 15];
[svgView_ addRequest: [NSURL URLWithString: [bundle pathForResource: @"t_layout" ofType: svg ]] seconds: 5];
实现类
@implementation RAWebView
//! Internal - process next request
- (void) nextRequest {
RAWebRequest *next = [[urlStack_ pop] retain];
if ( next == nil ) {
[self setHidden: TRUE];
} else {
[super loadRequest: [NSURLRequest requestWithURL: [next url]]];
[super setHidden: FALSE];
[super setUserInteractionEnabled: TRUE];
if ( 0 < [next periodSecs] ) {
int64_t delta = 1000000000;
delta *= [next periodSecs];
dispatch_after( dispatch_time( DISPATCH_TIME_NOW, delta),
dispatch_get_main_queue(),
^{ [self nextRequest]; } );
}
[next release];
}
}
//! Add RAWebRequest to queue
- (void) addRequest: (RAWebRequest*) web_request {
if ( urlStack_ == nil ) {
urlStack_ = [[D4iStack alloc] init];
[self setBackgroundColor: [UIColor clearColor]];
[self setOpaque: NO];
}
if ( 0 == [urlStack_ count] ) {
dispatch_after( dispatch_time( DISPATCH_TIME_NOW, 10000 ),
dispatch_get_main_queue(),
^{ [self nextRequest]; } );
}
[urlStack_ push: web_request];
}
//! Add RAWebRequest to queue
- (void) addRequest: (NSURL*) display_url seconds: (NSUInteger) period_secs {
RAWebRequest *request = [[RAWebRequest alloc] initWithUrl: display_url seconds: period_secs];
[self addRequest: request];
[request release];
}
//! On user touch, hide self and empty urlStack
- (UIView*) hitTest: (CGPoint)point withEvent:(UIEvent *)event {
[urlStack_ clear];
[self setHidden: TRUE];
return nil;
}
//! NSObject dealloc
- (void) dealloc {
[urlStack_ clear];
[urlStack_ release];
[super dealloc];
}
@end
@implementation RAWebRequest
@synthesize url = url_, periodSecs = periodSecs_;
//! Init with set values
- (id) initWithUrl: (NSURL*) display_url seconds: (NSUInteger) period_secs {
if (( self = [super init] )) {
url_ = [display_url retain];
periodSecs_ = period_secs;
}
return self;
}
//! NSObject dealloc
- (void) dealloc {
[url_ release];
[super dealloc];
}
@end