我是Xamarin.iOS初学者。我也没有太多的iOS原生经验。我试图隐藏并显示包含UILabel和UITextField的UIView。虽然视图的hidden属性设置为true,但它仍占用屏幕空间。如何删除此空间?如果我尝试将宽度约束设置为0以隐藏它然后再将其设置回原始值以显示它,它就不起作用。它继续保持在0。
另一个问题 - 当切换开启和关闭其可见性时,视图是否会保留其状态和行为?
提前感谢所有帮助..
答案 0 :(得分:1)
如果没有您的代码,很难说出解决方案。但是从你的问题我可以看到很少的解决方案,如:
您可以尝试更改主线程中的约束,更改约束后需要调用LayoutIfNeeded()
[Foundation.Export("layoutIfNeeded")]
public virtual Void LayoutIfNeeded ()
除此之外,您可以使用horizontal UIStackView
将UIView
的宽度设为0,同时隐藏并在显示时返回原始状态。
答案 1 :(得分:1)
即使您将控件的NSLayoutAnchor
设置为true,它仍然存在,但是无法看到。因此,如果你的第二个控件的约束依赖于第一个,它就不会改变它的位置。
将其设置回原始值以显示它,它不起作用。它继续保持在0。
您使用哪种约束?
如果您使用//Define a field
NSLayoutConstraint WidthConstraint = null;
//When you want to modify the width, try to disable the previous one
if (WidthConstraint != null)
{
WidthConstraint.Active = false;
}
WidthConstraint = Control.WidthAnchor.ConstraintEqualTo(0);
WidthConstraint.Active = true;
,则应在要修改之前禁用先前的约束。例如:
NSLayoutConstraint
如果您使用foreach (NSLayoutConstraint constraints in Control.Constraints)
{
if (constraints.FirstItem.IsEqual(Control) && constraints.FirstAttribute.Equals(NSLayoutAttribute.Width))
{
constraints.Constant = 0;
}
}
,则可以直接更改常量:
import requests, json, pprint
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
pagesize = 1000
api_url_base = "https://test/sepm/api/v1/"
authentication_url = "https://test/sepm/api/v1/identity/authenticate"
json_format = True
payload = {
"username" : "test",
"password" : "test",
"domain" : ""}
headers = {"Content-Type":"application/json"}
r = requests.post(authentication_url, verify=False, headers=headers,
data=json.dumps(payload))
api_token = (r.json()["token"])
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer
{0}'.format(api_token)}
def get_info(url,params):
api_url = url
params = params
response = requests.get(api_url, headers=headers,verify=False,
params=params)
if response.status_code == 200:
return json.loads(response.content.decode('utf-8'))
else:
return response.status_code
def aggregate(endpoint_info,numberOfElements):
itr =0
while itr <= (numberOfElements-1):
computerName=endpoints_info['content'][itr]['computerName']
ipAddresses=endpoints_info['content'][itr]['ipAddresses'][0]
logonUserName=endpoints_info['content'][itr]['logonUserName']
lastUpdateTime=endpoints_info['content'][itr]['creationTime']
agentVersion = endpoints_info['content'][itr]['agentVersion']
print(computerName, ipAddresses, logonUserName, lastUpdateTime, a
gentVersion)
itr = itr+1
groups_url = '{0}groups'.format(api_url_base)
fingerprint_url = '{0}policy-objects/fingerprints'.format(api_url_base)
endpoints_url = '{0}computers?'.format(api_url_base)
total_pages = get_info(endpoints_url,{'pageSize':pagesize})['totalPages']
itr = 1
while itr <= total_pages:
params = {'pageSize':pagesize, 'pageIndex':itr}
endpoints_info = get_info(endpoints_url,params)
numberOfElements = endpoints_info['numberOfElements']
itr = itr +1
if endpoints_info is not 200:
aggregate(endpoints_info,numberOfElements)
else:
print('[!] Request Failed, {0}')