Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.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/0/mercurial/2.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_Titanium_Appcelerator - Fatal编程技术网

Ios 钛合金,使用动画更改文本字段高度

Ios 钛合金,使用动画更改文本字段高度,ios,titanium,appcelerator,Ios,Titanium,Appcelerator,在Appcelerator Titanium(iOS项目)中,我有一个高度为50的TextField。TextField包含更多的文本,但它的高度设置为50,这让我可以使用TextField作为剩余文本的预览:在TextField下,我有一个按钮,当我点击这个按钮时,我想显示整个文本,因此,我想将TextField从当前高度设置为Ti.UI.SIZE。这可能吗?怎么用?我注意到一些iOS属性(例如anchorPoint),但我不明白它们是否对我的情况有用。如果需要多行和换行,则需要使用TextA

在Appcelerator Titanium(iOS项目)中,我有一个高度为50的
TextField
TextField
包含更多的文本,但它的高度设置为50,这让我可以使用
TextField
作为剩余文本的预览:在
TextField
下,我有一个按钮,当我点击这个按钮时,我想显示整个文本,因此,我想将
TextField
从当前高度设置为
Ti.UI.SIZE
。这可能吗?怎么用?我注意到一些iOS属性(例如anchorPoint),但我不明白它们是否对我的情况有用。

如果需要多行和换行,则需要使用
TextArea
而不是
TextField

我已经将
文本区域
添加到
视图
中,这样我就可以对其进行动画处理,使其同时展开和收缩

你可以试试这样的

// Create the text area for multiple lines and word wrapping.
var messageField = Ti.UI.createTextArea({
    backgroundColor: 'transparent',
    color: 'black',
    height: Ti.UI.SIZE, // Set here the height to SIZE and the view's height to the required one, ex. 50
    textAlign: 'left',
    value: 'This text should be displayed in more than one line in a text area, but that behavior is not supported by a text field, again, This text should be displayed in more than one line in a text area, but that behavior is not supported by a text field.',
    verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_TOP,
    width: '90%',
    font: { fontSize: 20 }
});

// Add the text area to a view to be able to animate it
var view = Titanium.UI.createView({
    height: 50, // Required height
    top: 250,
    width: '90%',
    borderColor: 'black',
    borderRadius: 10,
    borderWidth: 2,
});
view.add(messageField);

// Create animation object
var animation = Titanium.UI.createAnimation();
animation.duration = 1000; // Set the time of animation, 1000 --> 1 second

var button = Ti.UI.createButton({
    title: "Show More",
    font: { fontSize: 18 },
    width: 100,
    top: 200
});
var isExpanded = false;
button.addEventListener('click', function() { // Event listener for your button
    if(isExpanded) {
        isExpanded = false;
        animation.height = 50; // Set the animation height to 50 to shrink the view
        view.animate(animation); // Start animating the view to the required height
        button.title = "Show More";
    } else {
        isExpanded = true;
        animation.height = Ti.UI.SIZE; // Set the animation height to SIZE to make it expand
        view.animate(animation); // Start animating the view to the required height
        button.title = "Show Less";
    }
});

var win = Ti.UI.createWindow({
    backgroundColor: 'white'
});

win.add(button);
win.add(view);
win.open();

这没关系,但我想要一个动画,而不是那样改变高度:-)@3000我已经添加了动画代码,如果你还需要什么,请尝试告诉我。这很有趣,但它会导致另一个问题:我得到的是文本的结尾,而不是开头,因此没有“预览”有效性我认为实现这种行为的唯一方法是将
TextArea
scrollable
属性设置为false,但是用户在单击Show More按钮之前无法看到所有文本。在Tianium:D中经常会发生这种情况,我希望他们在下一个SDK中修复这种情况。