Исчезните в / содержании UIScrollView как Мобильный Safari, делает на его вкладке

var authors = [];
authors[0] = 1;
authors[1] = 2;

var arr = {
    "csrfmiddlewaretoken": getCookie('csrftoken'),
    "title": "dasf",
    "desct": "dasf",
    "content": "fdasf",
    "authors": authors
    };

$.ajax({
    url: '/api/save-post/',
    type: 'POST',
    data: arr,
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {
        alert(msg);
    }
});
13
задан Ajumal 27 April 2015 в 10:36
поделиться

2 ответа

UPDATE

I came up with another way to update alpha value of each page. When creating content view, I use KVO to addObserver with UIScrollView's contentOffset:

[self.scrollView addObserver:[self.contentViews objectAtIndex:i] 
                  forKeyPath:@"contentOffset" 
                     options:NSKeyValueObservingOptionNew
                     context:@selector(updateAlpha:)];

So that each of my contentViews will get the message when contentOffset changed:

- (void)observeValueForKeyPath:(NSString *)keyPath 
                      ofObject:(id)object 
                        change:(NSDictionary *)change 
                       context:(void *)context {
    [self performSelector:(SEL)context withObject:change];
}

And my contentViews can do the calculation and animate by themselves when scrolling:

- (void)updateAlpha:(NSDictionary *)change {
    CGFloat offset = [[change objectForKey:NSKeyValueChangeNewKey] CGPointValue].x;
    CGFloat origin = [self frame].origin.x;
    CGFloat delta = fabs(origin - offset);

    [UIView beginAnimations:@"Fading" context:nil];
    if (delta < [self frame].size.width) {
        self.alpha = 1 - delta/self.frame.size.width*0.7;
    } else {
        self.alpha = 0.3;
    }
    [UIView commitAnimations];
}

Of course, you will need to remove the observer when you remove the content view from superview, and add them again when new content view created.

Hope this help to those who want to do the same.

26
ответ дан 1 December 2019 в 20:57
поделиться

Как вы заметили по тому, как часто вызывается scrollViewDidScroll:, UIScrollView не просто запускает и забывает переход Core Animation: он вручную перемещает границы в соответствии с касаниями, ускорением и т. Д. Нет простого способа изменить это.

Однако, если вас завалили событиями прокрутки, вы можете попробовать следующий трюк:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
    if (timestamp - _savedTimestamp) < 0.1)
        return;
    _savedTimestamp = timestamp;

    // do the rest of your work here
}

H

2
ответ дан 1 December 2019 в 20:57
поделиться