水平UIcollectionView滚动从右到左开始

时间:2020-05-25 11:12:08

标签: swift xcode uicollectionview uicollectionviewcell

我确实希望视图在加载时首先显示正确的单元格,然后我应该从那里向左滚动我尝试这段代码,但没有成功

enter code here
import requests
import re
from bs4 import BeautifulSoup
from selenium import webdriver
import time

headers = {
 'User-Agnet' :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36'
}
driver = webdriver.Chrome('./chromedriver.exe')
driver.get('https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f')
driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click()
time.sleep(2)

driver.find_element_by_xpath('//*[@id="identifierId"]').send_keys('ID')
driver.find_element_by_xpath('//*[@id="identifierNext"]/span').click()
time.sleep(2)

driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys('PASSWORD')
driver.find_element_by_xpath('//*[@id="passwordNext"]/span/span').click()
time.sleep(2)

driver.get('https://music.youtube.com/history')
time.sleep(5)

headers = requests.utils.default_headers()
headers.update({'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36'})
s = requests.Session()
cookies = driver.get_cookies()
for cookie in cookies:
    s.cookies.set(cookie['name'], cookie['value'])
html = s.get('https://music.youtube.com/history',headers=headers).text

soup = BeautifulSoup(html, 'html.parser')

print("soup")
print(soup.prettify())

在视图加载时像这张照片一样显示右第一个单元格

enter image description here

2 个答案:

答案 0 :(得分:2)

由于UICollectionView从右向左水平滚动,因此您可以将集合视图设置为出现时显示为最大向右滚动!这样用户就可以开始从右向左滚动

YourCollectionView是所需的CollectionView的名称

YourObjectListData是该集合视图的数据源

self.YourCollectionView.reloadData()
self.YourCollectionView.scrollToItem(at: NSIndexPath(item: self.YourObjectListData.count - 1, section: 0) as IndexPath, at: .right, animated: false) 

答案 1 :(得分:-1)

这不是UICollection视图的通常行为,但是如何旋转和翻转您的collectionView,那么最后一个单元格将是您的第一个;)。

如果有兴趣,请检查CGAffineTransform(Rotation angle)CGAffineTransform(TranslationY)