-1

我试图将 aUIView移入while-loop. 它在视觉上不会移动UIView,我认为这很奇怪。根据我的经验,它在 Obj-C 中只是这样,为什么在 Obj-C 中会这样?它仅在循环完成时在视觉上移动它。我认为不需要代码,它只是移动它的一行。

编辑

要求的代码,所以你去:

while (!CGPointEqualToPoint(finder.center, endPoint)) {
    [finder setCenter:CGPointMake(finder.center.x+10, finder.center.y)];
}

1行。

EDOT

好的,这还不是全部,它是用于路径查找器的。但那条线是移动 UIView 的那条线,所以我认为这是我的问题中唯一相关的线。

4

3 回答 3

1

因为当您循环更新框架时,屏幕不会更新。iOS 自行决定何时更新屏幕。这就是为什么存在类似的方法setNeedsDisplay但不存在类似的方法display。因此,如果您在 while 循环中执行此操作,屏幕将仅更新一次。请参阅NSRunLoop文档。https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSRunLoop_Class/Reference/Reference.html

好像你想做这样的事情:

- (void)doSomeAnimation {
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.someView.frame = CGRectMake(self.someView.frame.origin.x + 10,
                                                          self.someView.frame.origin.y,
                                                          self.someView.frame.size.width,
                                                          self.someView.frame.size.height);
                     } 
                     completion:^(BOOL finished){
                         if ([self needsDoAnimation]) // while condition analog 
                         { 
                             [self doSomeAnimation]; 
                         }
                     }];
}

- (BOOL)needsDoAnimation {
    BOOL needsAnimation = (self.someView.frame.origin.x < 320); // some conditions
    return needsAnimation;
}

看看什么是主事件循环

https://developer.apple.com/library/ios/documentation/general/conceptual/Devpedia-CocoaApp/MainEventLoop.html

于 2013-10-08T12:41:10.717 回答
0

我不确定我是否真的理解你的问题。如果您想在特定的持续时间和特定的声誉中移动循环,为什么不编写一个方法来为您UIView的块内部UIAnimation设置动画,并且在您进入完成博客时在动画之后再次调用该方法。

- (void)animateMyView:(UIView *)view 
         withDuration:(float)duration 
            andRepeat:(int)repeat{

    [UIView animateWithDuration:duration animations:^{
        view.frame = CGRectMake(self.view.frame.origin.x,
                                  self.view.frame.origin.y + 20,
                                  self.view.frame.size.width,
                                  self.view.frame.size.height);
    } completion:^(BOOL finished) {

        if(repeat > 0){
           [self animateMyView:view 
                  withDuration:duration 
                     andRepeat:(repeat - 1)];
        }
    }];
}

这将在 y 轴上每次 20.0 移动您的视图。

于 2013-10-08T12:47:09.340 回答
0

If you want to animate the view into a new position, you can use :

[UIView animateWithDuration:2.0 animations:^{
  view.frame = finalPosition;
} completion:^(BOOL finished){
  // code to run when animation is done
}

reference : https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/occ/clm/UIView/animateWithDuration:animations:

于 2013-10-08T12:48:06.157 回答