我为我的应用程序创建了一个浮动视图,它总是显示在屏幕上。
现在我想让它的一半在我的屏幕外,当它是互动3-4秒。我认为我应该使用NSTimer隐藏这个视图,但这不是问题所在。
问题是如何将此视图的origin.x设置到屏幕外?我尝试在我的initWithSuperView中设置这样的框架:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenX = screenRect.origin.x;
[self setFrame:CGRectMake(-screenX - size.width, 0, size.width, size.height)];但是,它不起作用。我应该怎么做才能得到我想要的结果呢?有关更多信息,请参见下图:

发布于 2016-10-12 14:44:46
您可以使用类似于以下内容的uiview动画:
dispatch_async(mainQueue, ^{
__weak __typeof(self) weakSelf = self;
[UIView animateWithDuration:3.f animations:^{
// change uiview frame here
weakSelf.frame = hiddenFrame;
} completion:^(BOOL finished) {
// setup completion
[weakSelf.view layoutIfNeeded];
}];
});此外,您还可以将NSLayoutConstraint设置为uiview的x约束,并在需要时使用负值更新它。
https://stackoverflow.com/questions/40001292
复制相似问题