当前位置: 首页>>代码示例>>C#>>正文


C# UITextView.GetOffsetFromPosition方法代码示例

本文整理汇总了C#中UITextView.GetOffsetFromPosition方法的典型用法代码示例。如果您正苦于以下问题:C# UITextView.GetOffsetFromPosition方法的具体用法?C# UITextView.GetOffsetFromPosition怎么用?C# UITextView.GetOffsetFromPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UITextView的用法示例。


在下文中一共展示了UITextView.GetOffsetFromPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Changed

		async public override void Changed (UITextView textView)
		{
			string text = StringUtils.TrimWhiteSpaceAndNewLine (textView.Text);
			UpdateCharacterCount(text);
			Validate ();

			if (SuggestionsCollectionView != null) {
				if (text.Length <= 2 || !text.Contains ("@")) {
					SuggestionsCollectionView.Hidden = true;
					return;
				}
					

				int cursorPositionEarly = (int)textView.GetOffsetFromPosition (textView.BeginningOfDocument, textView.SelectedTextRange.Start);

				if (cursorPositionEarly <= 0)
				{
					return;
				}

				string charToTest = textView.Text.Substring (cursorPositionEarly - 1, 1);
				if (charToTest != "@" && charToTest != " ") {

					string beforeTextEarly = textView.Text.Substring (0, cursorPositionEarly);
					string strippedToLastSpaceOnward = beforeTextEarly;
					if (strippedToLastSpaceOnward.IndexOf ("") > -1 && strippedToLastSpaceOnward.Length > 2) {
						strippedToLastSpaceOnward = strippedToLastSpaceOnward.Substring (strippedToLastSpaceOnward.LastIndexOf (" ") + 1);
					}

					if (strippedToLastSpaceOnward.Length > 1 && strippedToLastSpaceOnward.Substring (0, 1) == "@") {

						try
						{
							List<User> users = await TenServices.SearchFollowingUsers(strippedToLastSpaceOnward.Substring(1));


							SuggestionsCollectionViewDelegate del = new SuggestionsCollectionViewDelegate();
							del.ItemSelectedAction += delegate (int index)
							{
								int cursorPosition = (int)textView.GetOffsetFromPosition(textView.BeginningOfDocument, textView.SelectedTextRange.Start);
								string currentText = textView.Text;
								string beforeText = currentText.Substring(0, cursorPosition);
								beforeText = beforeText.Substring(0, beforeText.LastIndexOf('@'));
								string afterText = currentText.Substring(cursorPosition);

								currentText = currentText.Substring(0, cursorPosition);
								textView.Text = beforeText + "@" + users[index].username + " " + afterText;

								SuggestionsCollectionView.Hidden = true;

								UpdateCharacterCount(textView.Text);
							};

							SuggestionsCollectionView.Delegate = del;
							SuggestionsCollectionView.DataSource = new SuggestionsCollectionViewDataSource(users);
							SuggestionsCollectionView.Hidden = false;
						}
						catch (RESTError e)
						{
							Console.WriteLine(e.Message);
						}
						finally
						{
							UpdateCharacterCount(text);
						}
					} else { 
						SuggestionsCollectionView.Hidden = true;
					}
				}
				UpdateCharacterCount(text);
			}
		}
开发者ID:natevarghese,项目名称:XamarinTen,代码行数:72,代码来源:AddACaptionTextViewDelegate.cs


注:本文中的UITextView.GetOffsetFromPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。