我想使用缩放增加图像。我做了这个,并且这相当于图像类型大小的大小,但我仍然像这样的变化顶部背景?我该怎么做?
我在viewDidLoad中的imageView
import initialState from '../store/initialState';
import * as ActionTypes from '../actionTypes/authActionTypes';
const authReducer = function authReducer(state = initialState.auth, action) {
switch (action.type) {
case ActionTypes.LOGIN_REQUEST:
return Object.assign({}, state, {
isLoggingIn: true,
isLoggedIn: false,
});
case ActionTypes.LOGOUT:
return Object.assign({}, state, {
isLoggedIn: false,
isLoggingIn: false,
});
case ActionTypes.LOGIN_FAILURE:
return Object.assign({}, state, {
error: action.error,
isLoggingIn: false,
isLoggedIn: false,
});
case ActionTypes.LOGIN_SUCCESS:
return Object.assign({}, state, {
isLoggedIn: true,
isLoggingIn: false,
response: action.response,
});
default:
return state;
}
};
export default authReducer;
答案 0 :(得分:2)
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(contentsOfFile: document.documentImageURL)
imageView = UIImageView(image: image)
imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
scrollView = UIScrollView(frame: view.bounds)
scrollView.delegate = self
scrollView.backgroundColor = UIColor(red: 129/255.0, green: 130/255.0, blue: 130/255.0, alpha: 1.0)
scrollView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
scrollView.showsHorizontalScrollIndicator = false
scrollView.showsVerticalScrollIndicator = false
scrollView.addSubview(imageView)
view.addSubview(scrollView)
newZoomScale()
scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false)
setGesture()
setNavigationBar()
}
private func newZoomScale() {
let imageViewSize = imageView.bounds.size
let scrollViewSize = scrollView.bounds.size
let widthScale = scrollViewSize.width / imageViewSize.width
let heightScale = scrollViewSize.height / imageViewSize.height
scrollView.minimumZoomScale = min(widthScale, heightScale)
scrollView.zoomScale = 1.0
}
func scrollViewDidZoom(scrollView: UIScrollView) {
let imageViewSize = imageView.frame.size
let scrollViewSize = scrollView.bounds.size
let verticalPadding = imageViewSize.height < scrollViewSize.height ? (scrollViewSize.height - imageViewSize.height) / 2 : 0
let horizontalPadding = imageViewSize.width < scrollViewSize.width ? (scrollViewSize.width - imageViewSize.width) / 2 : 0
self.scrollView.contentInset = UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
}