ti-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTitanium SDK UI expert
Titanium SDK UI专家
A practical guide to Titanium SDK UI. Covers layouts, event handling, animations, performance, and platform-specific components for iOS and Android.
这是一份Titanium SDK UI实用指南,涵盖iOS和Android平台的布局、事件处理、动画、性能优化以及平台特定组件相关内容。
Project detection
项目检测
:::info auto-detects titanium projects
This skill detects Titanium projects and provides UI guidance.
Detection happens automatically. You do not need to run a command.
Titanium project indicator:
- (required for all Titanium projects)
tiapp.xml
Applicable to both:
- Alloy projects (app/ folder structure)
- Classic projects (Resources/ folder)
Behavior based on detection:
- Titanium detected: Provide UI guidance for Alloy and Classic, ListView/TableView patterns, and platform differences
- Not detected: State this is for Titanium projects only and skip UI guidance :::
:::info 自动检测Titanium项目
该技能可检测Titanium项目并提供UI开发指导。
检测过程自动进行,无需执行命令。
Titanium项目标识:
- (所有Titanium项目必备文件)
tiapp.xml
适用于两种项目类型:
- Alloy项目(app/目录结构)
- 经典项目(Resources/目录)
基于检测结果的行为:
- 检测到Titanium项目:提供Alloy和经典项目的UI指导、ListView/TableView模式以及平台差异说明
- 未检测到Titanium项目:说明本技能仅适用于Titanium项目,不提供UI指导 :::
Quick reference
快速参考
| Topic | Reference |
|---|---|
| App structures | application-structures.md |
| Layouts, positioning, units | layouts-and-positioning.md |
| Events, bubbling, lifecycle | event-handling.md |
| ScrollView vs ScrollableView | scrolling-views.md |
| TableView | tableviews.md |
| ListView templates, performance | listviews-and-performance.md |
| Touch, swipe, pinch, gestures | gestures.md |
| Orientation handling | orientation.md |
| Custom fonts, attributed strings | custom-fonts-styling.md |
| Animations, 2D/3D matrices | animation-and-matrices.md |
| Icons, splash screens, densities | icons-and-splash-screens.md |
| Android action bar, themes | platform-ui-android.md |
| iOS navigation, 3D Touch | platform-ui-ios.md |
| VoiceOver, TalkBack, a11y | accessibility-deep-dive.md |
| 主题 | 参考文档 |
|---|---|
| 应用结构 | application-structures.md |
| 布局、定位、单位 | layouts-and-positioning.md |
| 事件、冒泡、生命周期 | event-handling.md |
| ScrollView vs ScrollableView | scrolling-views.md |
| TableView | tableviews.md |
| ListView模板、性能 | listviews-and-performance.md |
| 触摸、滑动、捏合、手势 | gestures.md |
| 屏幕方向处理 | orientation.md |
| 自定义字体、富文本字符串 | custom-fonts-styling.md |
| 动画、2D/3D矩阵 | animation-and-matrices.md |
| 图标、启动页、屏幕密度 | icons-and-splash-screens.md |
| Android Action Bar、主题 | platform-ui-android.md |
| iOS导航、3D Touch | platform-ui-ios.md |
| VoiceOver、TalkBack、无障碍 | accessibility-deep-dive.md |
Critical rules
关键规则
Performance
性能
- Do not use in ListViews. It causes jerky scrolling. Use fixed heights.
Ti.UI.SIZE - Prefer ListView over TableView for new apps with large datasets.
- Batch updates with to reduce bridge overhead.
applyProperties - Avoid WebView inside TableView. It kills scrolling performance.
- 请勿在ListView中使用,这会导致滚动卡顿,应使用固定高度。
Ti.UI.SIZE - 对于包含大数据集的新应用,优先使用ListView而非TableView。
- 使用批量更新属性,减少桥接层开销。
applyProperties - 避免在TableView内嵌套WebView,这会严重影响滚动性能。
iOS accessibility
iOS无障碍访问
- Do not set accessibility properties on container views. It blocks child interaction.
- Do not set on text controls on Android. It overrides visible text.
accessibilityLabel
- 请勿在容器视图上设置无障碍属性,这会阻止子视图的交互。
- 请勿在Android的文本控件上设置,这会覆盖可见文本内容。
accessibilityLabel
Layout
布局
- Use units for cross-platform consistency.
dp - Android ScrollView is vertical or horizontal, not both. Set .
scrollType
- 使用单位确保跨平台一致性。
dp - Android的ScrollView仅支持垂直或水平单一方向滚动,需设置。
scrollType
Platform-specific properties
平台特定属性
:::danger critical: platform-specific properties require modifiers
Using or properties without platform modifiers will crash cross-platform compilation.
Ti.UI.iOS.*Ti.UI.Android.*Example of the damage:
javascript
// Wrong: adds Ti.UI.iOS to an Android build
const win = Ti.UI.createWindow({
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
})Correct approaches:
Option 1: TSS modifier (Alloy projects):
tss
"#mainWindow[platform=ios]": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}Option 2: Conditional code:
javascript
if (OS_IOS) {
$.mainWindow.statusBarStyle = Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}Properties that always require platform modifiers:
- iOS: ,
statusBarStyle,modalStyle, anymodalTransitionStyleTi.UI.iOS.* - Android: config, any
actionBarconstantTi.UI.Android.*
For platform-specific UI patterns, see platform-ui-ios.md and platform-ui-android.md.
:::
:::danger 重要提示:平台特定属性需使用修饰符
直接使用或属性而不添加平台修饰符会导致跨平台编译失败。
Ti.UI.iOS.*Ti.UI.Android.*错误示例:
javascript
// 错误:在Android构建中添加了Ti.UI.iOS相关属性
const win = Ti.UI.createWindow({
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
})正确实现方式:
方式1:TSS修饰符(Alloy项目):
tss
"#mainWindow[platform=ios]": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}方式2:条件判断代码:
javascript
if (OS_IOS) {
$.mainWindow.statusBarStyle = Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}必须添加平台修饰符的属性:
- iOS: ,
statusBarStyle,modalStyle, 所有modalTransitionStyle属性Ti.UI.iOS.* - Android: 配置, 所有
actionBar常量Ti.UI.Android.*
关于平台特定UI模式,请参考platform-ui-ios.md和platform-ui-android.md。
:::
Event management
事件管理
- Remove global listeners (,
Ti.App,Ti.Gesture) on pause to save battery.Ti.Accelerometer - Input events bubble up. System events do not.
- 在应用暂停时移除全局监听器(、
Ti.App、Ti.Gesture)以节省电量。Ti.Accelerometer - 输入事件会向上冒泡,系统事件不会。
App architecture
应用架构
- Limit tabs to 4 or fewer for better UX across platforms.
- Use NavigationWindow for iOS hierarchical navigation.
- Handle to prevent unexpected exits.
androidback
- 标签栏的标签数量限制在4个以内,以确保跨平台的良好UX。
- iOS平台使用NavigationWindow实现层级导航。
- 处理事件,防止应用意外退出。
androidback
Platform differences summary
平台差异总结
| Feature | iOS | Android |
|---|---|---|
| 3D Matrix | Full support | No support |
| Pinch gesture | Full support | Limited |
| ScrollView | Bidirectional | Unidirectional |
| TableView | Full support | Full support |
| ListView | Full support | Full support |
| Default template image | Left side | Right side |
| ListView action items | Swipe actions | No |
| Modal windows | Fills screen, covers tab bar | No effect (always full) |
| Navigation pattern | NavigationWindow | Back button + Menu |
| 功能 | iOS | Android |
|---|---|---|
| 3D矩阵 | 完全支持 | 不支持 |
| 捏合手势 | 完全支持 | 支持有限 |
| ScrollView | 双向滚动 | 单向滚动 |
| TableView | 完全支持 | 完全支持 |
| ListView | 完全支持 | 完全支持 |
| 默认模板图片位置 | 左侧 | 右侧 |
| ListView操作项 | 滑动操作 | 无 |
| 模态窗口 | 全屏显示,覆盖标签栏 | 无特殊效果(始终全屏) |
| 导航模式 | NavigationWindow | 返回按钮 + 菜单 |
UI design workflow
UI设计流程
- Choose app structure: tab-based or window-based
- Pick a layout mode: composite, vertical, or horizontal
- Decide sizing: or
SIZEbased on component defaultsFILL - Plan events: bubbling, app-level events, lifecycle
- Optimize performance: templates, batch updates
- Apply accessibility per platform
- Add motion: animations, 2D/3D transforms, transitions
- 选择应用结构:标签栏式或窗口式
- 选择布局模式:复合、垂直或水平
- 确定尺寸:根据组件默认值选择或
SIZEFILL - 规划事件:冒泡机制、应用级事件、生命周期事件
- 性能优化:模板使用、批量更新
- 按平台要求适配无障碍访问
- 添加动效:动画、2D/3D变换、过渡效果
Searching references
参考文档搜索
When you need specific patterns, grep these terms in the reference files:
- App structure: ,
TabGroup,NavigationWindow,modal,execution contextandroidback - Layouts: ,
dp,Ti.UI.SIZE,Ti.UI.FILL,composite,verticalhorizontal - Events: ,
addEventListener,cancelBubble,bubblingTi.App.fireEvent - TableView: ,
TableView,TableViewRow,setData,appendRowclassName - ListView: ,
ItemTemplate,bindId,setItems,updateItemAtmarker - Gestures: ,
swipe,pinch,longpress,shakeaccelerometer - Animation: ,
animate,create2DMatrix,create3DMatrixautoreverse - Fonts: ,
fontFamily,PostScript,createAttributedStringATTRIBUTE_ - Icons/splash: ,
DefaultIcon,appicon,nine-patch,drawable,splash,iTunesArtworkadaptive - Android: ,
Action Bar,onCreateOptionsMenu,theme,Material3talkback - iOS: ,
3D Touch,Popover,SplitWindow,badgeNavigationWindow - Accessibility: ,
accessibilityLabel,VoiceOver,TalkBackaccessibilityHidden
当需要特定模式时,可在参考文档中搜索以下关键词:
- 应用结构:,
TabGroup,NavigationWindow,modal,execution contextandroidback - 布局:,
dp,Ti.UI.SIZE,Ti.UI.FILL,composite,verticalhorizontal - 事件:,
addEventListener,cancelBubble,bubblingTi.App.fireEvent - TableView: ,
TableView,TableViewRow,setData,appendRowclassName - ListView: ,
ItemTemplate,bindId,setItems,updateItemAtmarker - 手势:,
swipe,pinch,longpress,shakeaccelerometer - 动画:,
animate,create2DMatrix,create3DMatrixautoreverse - 字体:,
fontFamily,PostScript,createAttributedStringATTRIBUTE_ - 图标/启动页:,
DefaultIcon,appicon,nine-patch,drawable,splash,iTunesArtworkadaptive - Android: ,
Action Bar,onCreateOptionsMenu,theme,Material3talkback - iOS: ,
3D Touch,Popover,SplitWindow,badgeNavigationWindow - 无障碍访问:,
accessibilityLabel,VoiceOver,TalkBackaccessibilityHidden
Related skills
相关技能
For work beyond UI components, use these skills:
| Task | Use this skill |
|---|---|
| Project architecture, services, memory cleanup | |
| Native features (camera, location, push, media) | |
| Alloy MVC, data binding, widgets | |
若需处理UI组件之外的工作,可使用以下技能:
| 任务 | 对应技能 |
|---|---|
| 项目架构、服务、内存清理 | |
| 原生功能(相机、定位、推送、媒体) | |
| Alloy MVC、数据绑定、组件 | |